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.
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.
是的,这是正确的方法,就像SO中的编辑链接一样...只需确保在处理之前验证控制器中的ID
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)
This is correct... Your code would throw an error
<a href="<?php echo site_url("post/edit/{$row->id}"); ?>">Edit</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.