Link to view inside subfolder does not display correctly |
09-06-2016, 07:38 PM
(This post was last modified: 09-06-2016, 10:04 PM by 678238515702801. Edit Reason: Plea for help my crops are dying )
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';
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.
(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 = '')
[Just a programmer] [/Just a programmer]
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 / What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |