Query Strings are a total turn off to CodeIgniter |
[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'); }
[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-gui.../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.
[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
[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.
[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!
[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') |
Welcome Guest, Not a member yet? Register Sign In |