![]() |
Query Strings are a total turn off to CodeIgniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Query Strings are a total turn off to CodeIgniter (/showthread.php?tid=8685) |
Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]floweringmind88[/eluser] I have spent days trying to just send some variables to the page I am at. It would be really nice if there was a good tutorial on how you do this as this seems to be the method that you think is best. For example I go to the page: http://domain.com/page/ Now I want send a variable but I always get a 404 page not found: http://domain.com/page/variable This is how my code looks: class Welcome extends Controller { function Welcome() { parent::Controller(); } function index() { $product_id = $this->uri->segment(2); $this->load->view('header'); $this->load->view('welcome'); $this->load->view('footer'); } Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]MCrittenden[/eluser] I believe you're getting a 404 because if there is anything after the controller name in the query string (in your case, the thing after is "variable") it assumes it's a function of that controller. So it's looking for a function named variable and freaking out because there's not one. Read the URL section of the user guide for more info: http://ellislab.com/codeigniter/user-guide/general/urls.html Try linking to http://domain.com/page/index/variable instead, and change your uri call from "segment(2)" to "segment(3)". That should do it. Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]floweringmind88[/eluser] Finally! I didn't get that you had to pass the function first in the segment and then variable. Thanks so much. Chris Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]MCrittenden[/eluser] No problem. Welcome to CI! Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]gtech[/eluser] you don't have to use url segment if you don't want to either Code: function index($product_id) will achieve the same thing. Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]MCrittenden[/eluser] [quote author="gtech" date="1211919526"]you don't have to use url segment if you don't want to either Code: function index($product_id) will achieve the same thing.[/quote] I like that! What if no param is passed, could you change $product_id into $product_id=null in the function declaration to handle either case? I'm still a CI newbie too! Query Strings are a total turn off to CodeIgniter - El Forum - 05-27-2008 [eluser]gtech[/eluser] yes you can default the parameter(s) like you suggest. Code: function index($product_id=NULL,$somthing_else=2,$and_another='tree') |