is there a way to make second segment not to look for a function ? |
[eluser]netameta1[/eluser]
What i mean is right now my website is set up to redirect to controller name home so basically when i type www.domain.com/home or www.domain.com i will end up in home controller. Now in that controller // page i am loading some tables from database - that data will require pagination from time to time. which mean the link of the pagination is : www.domain.com/home/3/ Now the way i have it set up when this address is being accessed CI goes to home controller and look for function name 3. my question is: is there a way to make it so CI will treat the 3 as a variable instead of a functions. Also is there a way to do it just for that section of the website (i am asking this because i have my whole admin panel set up already with the normal "www.domain.com/admin/function/variable" ) Thanks in advanced for any help.
[eluser]netameta1[/eluser]
sr.research associate. my routs file is now as this: Code: $route['default_controller'] = "home"; doesn't that suppose to route numbers after home/2 to home controller ?
[eluser]CroNiX[/eluser]
[quote author="netameta1" date="1351732513"] doesn't that suppose to route numbers after home/2 to home controller ? [/quote] Yes, but unless you change CI's behavior of expecting url segment 2 to be a method in the controller (which _remap() does) then you have to pass it to a method. It's just hidden in the url. Try something like Code: $route['home/(:num)'] = "home/page/$1"; and then create a "page" method. Code: public function page($page = 0) Yes it will work if you also go to /home/page/4, but you won't create those links so no one will know. You'll create links like /home/4. If that's a problem you can always verify that $this->uri->segment(2) !== 'page' and reject it if it is as that means that was entered in the url.
[eluser]netameta1[/eluser]
What i did was: $route['home/(:num)'] = "home"; if the address now is www.domain.com/home/3 - it will redirect to home which is what i wanted + segment 2 will be passed. so when i echo $this->uri->segment(2) - on home - index function i get 3 which is exactly what i am looking for. i went farther and and added the sorting after the number and this also works as segment 3. Anyways thanks very much for your help, |
Welcome Guest, Not a member yet? Register Sign In |