Use function instead of a controller - 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: Use function instead of a controller (/showthread.php?tid=60147) |
Use function instead of a controller - El Forum - 01-25-2014 [eluser]ruiganga[/eluser] Hi This is my first CI project so please forgive my dumbness. After viewing 3 full tutorials, I've designed my app like this: Main Controller - index function show app home - login function show form - logout function kills session and redirect to app root Looks simple. I can do it if Login and Logout are Controllers, but instead, I wish them to be functions of Main controller. site.com -> execute Main Controller index function I expect to site.com/login -> execute Main Controller login function Any way to do this? thanks for any help Use function instead of a controller - El Forum - 01-25-2014 [eluser]CroNiX[/eluser] Have a look at routes in the user guide. Use function instead of a controller - El Forum - 01-26-2014 [eluser]ruiganga[/eluser] Oh yeah. very simple indeed after knowing what routes are for. The only code I needed was this: Code: $route['logout'] = "main/logout"; Thanks. But now I want that site.com/main/logout to not exist, or in other words, at least redirect to a new url. I've couldn't accomplish this with routes. Should I use the controller instead? how? Thanks for any help. Use function instead of a controller - El Forum - 01-26-2014 [eluser]ruiganga[/eluser] Routing is cool Here is the code I use to route any time main is in the url Code: $route['main/(:any)'] = "main/redirect"; Now in the Redirect FUNCTION I need to catch the any part to redirect to the correct page. Any tip for me? Use function instead of a controller - El Forum - 01-26-2014 [eluser]ruiganga[/eluser] I got the solution as: Code: // first in the route I've written If anyone has a tip to do it more intelligently I appreciate. I'm starting loving this Thanks to CroNiX for pointing me the routes Use function instead of a controller - El Forum - 01-26-2014 [eluser]CroNiX[/eluser] One thing with routes...you need to have the order go from the uri with the most segments, to least. Code: $route['main/(:any)'] = "main/redirect"; //two segments, main + (:any) Code: $route['main/(:any)'] = "main/redirect/$1"; //$1 will be (:any) Code: function redirect($url = null) //$url is (:any) from the route Code: redirect($this->uri->segment(2)); //redirects to base_url() + segments Use function instead of a controller - El Forum - 02-06-2014 [eluser]t'mo[/eluser] [quote author="ruiganga" date="1390750844"]... If anyone has a tip to do it more intelligently I appreciate. I'm starting loving this Thanks to CroNiX for pointing me the routes [/quote] Check out CodeIgniter's "remap" function here |