3

I have a list of posts and an edit link for each. When clicking edit it goes to a page where I can edit the specific post I clicked on. For this I will have to pull from the db the id of the post.

Would this be the correct way to do it?

<a href="<?php echo site_url("post/edit/$row->id"); ?>">Edit</a>

post is my controller, edit is my function, and $row->id should pull the id of the post.

1
  • 1
    Hover the edit link of your question to know the answer! ;-) Commented Jan 9, 2011 at 19:52

4 Answers 4

7

Yes, it seems correct to do

<a href="<?php echo site_url("post/edit/".$row->id); ?>">Edit</a> 

Just make sure that your action method (edit in this case) accepts an argument with the post id that you need to fetch.

Sign up to request clarification or add additional context in comments.

1 Comment

how do we receive that value from url ?
2

Yes this is the right way to do it, just like the edit link in SO...just make sure to validate the ID in your controller before processing

Comments

2

PHP won't interpret $row->id correctly within your string. you need to concatenate it at the end, EG: site_url("post/edit/".$row->id)

1 Comment

Sure? no, I haven't tested his code. Had errors previously when I tried to use objects within a string? Yes, I have.
2

This is correct... Your code would throw an error

<a href="<?php echo site_url("post/edit/{$row->id}"); ?>">Edit</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.