Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter passing variable to URL

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.

like image 747
CyberJunkie Avatar asked Feb 09 '26 16:02

CyberJunkie


2 Answers

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.

like image 122
Jose Armesto Avatar answered Feb 12 '26 15:02

Jose Armesto


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

like image 29
ifaour Avatar answered Feb 12 '26 15:02

ifaour