URI Segments only grabbing first number |
[eluser]redlogic[/eluser]
Hello, I'm still fairly new to CI but been coding in PHP for a while. I've been using the URI segments to pass variables instead of query strings, but it only seems to grab the first digit. So for example if the address is: http://localhost/index.php/site/record/3 This will pull record number 3 from the database. However if it is: http://localhost/index.php/site/record/39 It still pulls record 3 from the database. Seems work fine from 0-9 but when it get to double figures it won't work. Any ideas what I'm missing? Not sure what code you need but here's my Site controller: Code: <?php Thanks!
[eluser]WanWizard[/eluser]
You are making it a lot more complicated then needed. With a URL like http://localhost/index.php/site/record/39, CI will take care of the routing to controller site, method record(). You then define the method: Code: function record( $id = FALSE )
[eluser]redlogic[/eluser]
Story of my life :roll: Thanks for the post, I thought there must be a simpler way of doing it, I just, well, didn't know what it was. I could still use some help on the original question about why the Code: $this->uri->segment(2) Any ideas?
[eluser]Phil Sturgeon[/eluser]
[quote author="redlogic" date="1284575098"]Story of my life :roll: Thanks for the post, I thought there must be a simpler way of doing it, I just, well, didn't know what it was. I could still use some help on the original question about why the Code: $this->uri->segment(2) Any ideas?[/quote] You are accessing a string (even if it contains a number, its a string) via array syntax: Code: $get = $this->uri->segment(3); // 39
[eluser]redlogic[/eluser]
Right, yep I'm an idiot. Removed that and it works fine now, thanks! Just changed: Code: $rec_value = $get['record']; // get uri segment value to Code: $rec_value = $get; // get uri segment value That'll teach me to cut and paste code. |
Welcome Guest, Not a member yet? Register Sign In |