Welcome Guest, Not a member yet? Register   Sign In
Link to view inside subfolder does not display correctly
#1

(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/
   application/
       views/
           pages/
               item-1.php    
               item-2.php
               item-2/
                   subitem-1.php

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/';
$route['(:any)'] = $controller_views.'$1';
$route['pages/(:any)'] = $controller_views.'$1';
$route['item-2/(:any)'] = $controller_views.'item-2/$1';

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE

.htaccess

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /practice/

# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /practice/$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /practice/index.php/$1 [L]
</IfModule>

Controller

PHP Code:
<?php
class Pages extends CI_Controller
{
 
   function __construct()
 
   {
 
       parent::__construct();
 
   }

 
   public function view($page 'welcome_message')
 
   {
 
       if(!file_exists(APPPATH.'views/pages/'.$page.'.php'))
 
       {
 
           show_404();
 
       }

 
       $this->load->view('templates/header'$data);
 
       $this->load->view('pages/'.$page$data);
 
       $this->load->view('templates/footer'$data);
 
   }


welcome_message.php
Code:
<div id="container">
   <ul>
       <li>
           <a href='item-1'>Item 1</a>
       </li>
       <li>
           <a href='item-2'>Item 2</a>
       </li>
       <li>
           <a href='item-2/subitem-1'>Item 2/SubItem-2</a>
       </li>
   </ul>
</div>

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';
$route['(:any)'] = 'pages/view/$1'
Reply


Messages In This Thread
Link to view inside subfolder does not display correctly - by 678238515702801 - 09-06-2016, 07:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB