![]() |
Getting variable from uri into controller, then model, then view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Getting variable from uri into controller, then model, then view (/showthread.php?tid=33126) |
Getting variable from uri into controller, then model, then view - El Forum - 08-16-2010 [eluser]ToddyBoy[/eluser] I've been racking my brain for a few hours with this and it's starting to hurt. I'm sure it's a simple solution. I have a uri - www.mysite.com/lms/listings/edit/3 I have a route Code: $route['lms/listings/edit/:num'] = "lms/listings/edit_listing/$1"; The controller Code: function edit_listing($id) The model Code: function edit($id) When I open the edit_listing view, I have this code Code: <?php There will be more input fields in the form, I just put field in there to test that I can get the data, which I can't. I am getting an error when the page loads. A PHP Error was encountered Severity: Notice Message: Undefined index: listing_address Filename: lms/edit_listing.php Line Number: 72 The head bashing on the table bit is that I have run something nearly exactly the same as this, but without having to rely on the segment from the URI to pass through the chain of events to produce data from the database using basically the same code as above. I have the URI helper autoloaded so I don't think that is the problem. I don't need to run a loop as there is only 1 row of data from the table being returned from the model. Can anyone save my head from further torture? Getting variable from uri into controller, then model, then view - El Forum - 08-16-2010 [eluser]ToddyBoy[/eluser] After reading more about URI segments, I changed the controller to this. Code: function edit_listing() I didn't think I had to explicitly assign the URI segment to a variable to use it in the model. I thought that if I put a variable name when calling the function, it can be used. Doesn't matter. The main thing is, it works and my head can now start to heal. |