Link to view inside subfolder does not display correctly - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Link to view inside subfolder does not display correctly (/showthread.php?tid=66116) |
Link to view inside subfolder does not display correctly - 678238515702801 - 09-06-2016 I need to show a view that is inside a subfolder. Just please tell me straight if "controller/method" is the only way and that "subfolder/view_file" is not possible in this context. Here is my views structure: Code: practice/ PROBLEM: I am able to show the top-level "pages/item-1.php" and "pages/item-2.php" but when I try to show "pages/item-2/subitem-1.php", it just shows the page for "pages/item-2.php". I want "pages/item-2/subitem-1.php" to be shown correctly. However it is not. routes.php PHP Code: $controller_views = 'pages/view/'; .htaccess Code: <IfModule mod_rewrite.c> Controller PHP Code: <?php welcome_message.php Code: <div id="container"> I do not understand, when I visit Pages::view() with URL "item-2/subitem-1" the variable $page=="item-2" when in my routes.php it is declared as "$route['item-2/(:any)'] = $controller_views.'item-2/$1';" so I expect it will find the view. I have also tried doing this just to hardcode catch "pages/view/item-2/subitem-1" and still 404. PHP Code: $route['pages/(:any)/(:any)'] = 'pages/view/$1/$2'; RE: Link to view inside subfolder does not display correctly - Wouter60 - 09-06-2016 It has to do with the way CI handles URL's, namely in segments. The first segment is the controller. The seconde segment is the method inside that controller All subsequent segments are parameters for the method. So, the url "page/view/item-2/subitem-1" has 2 parameters, where your view method is expecting only one. You should find a way to combine the segments that follow after segment 2. See documentation about the URI class. RE: Link to view inside subfolder does not display correctly - InsiteFX - 09-07-2016 See the CodeIgniter Users Guide: URI Class PHP Code: $product_id = $this->uri->segment(3, 0); RE: Link to view inside subfolder does not display correctly - Joel Catantan - 09-07-2016 (09-06-2016, 07:38 PM)678238515702801 Wrote: I need to show a view that is inside a subfolder. Try: routes.php PHP Code: $route['pages/(:any)'] = 'pages/view/$1'; Pages.php (Controller) PHP Code: public function view($page, $subpage = '') RE: Link to view inside subfolder does not display correctly - InsiteFX - 09-08-2016 It will never get to the second /(:any) because the first one will always execute any is a catch all parameter in the routes. This is why I mentioned the uri segment method. If he wants multiple parameters then use /(.+) instead of any, it will split the parameters after the / |