Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Simple sub-directory pages

$
0
0
Hello, As I am a beginer with CI, I am having a issue by defining sub pages which are in the sub folders.

What I want :
  • Directory should be like : application/views/pages/hosting/hosting-about.php
I am successfully done working with : application/views/pages/aboutme.php

My Pages controller :
Code:
class Pages extends CI_Controller{

     public function view($page = 'home'){

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

       $data['title'] = ucfirst($page);

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

     }

     // public function subview($page = 'hosting'){
     //
     //   if(!file_exists(APPPATH.'views/pages/hosting/'.$page.'.php')){
     //     show_404();
     //   }
     //
     //   $data['title'] = ucfirst($page);
     //
     //   $this->load->view('partials/header');
     //   $this->load->view('pages/hosting/'.$page, $data);
     //   $this->load->view('partials/footer');
     //
     // }

   }

My Routes :
Code:
$route['default_controller'] = 'pages/view';


$route['(:any)'] = 'pages/view/$1';
//$route['(:any)'] = 'pages/subview/$1';
//$route['hosting/(:any)'] = 'hosting/view/$1';
//$route['hosting/(:any)'] = 'pages/hosting/view/$1';
//$route['(:any)/(:any)'] = "pages/hosting/view/$1";


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


With this configuration I can access : http://localhost/mysite/contact/
But I want to access like this : http://localhost/mysite/hosting/hosting-about.php

There is no internal relation between pages like parent or child, I just want to access through the sub folder within the pages folder.

As I am new with CI, please help me with the broad explanation and from best practice perspectives. 
Thanks in Advance !

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>