简体   繁体   中英

Codeigniter - Routing to subfolders not working

Hello im having an issue here im new in learning codeigniter but my main problem is i cannot locate the url i want to have like for this:

I need to type http://localhost/ciHrs/admin/pages whereas i only want to get the url http://localhost/ciHrs/admin/ please kindly explain how can I access this url. and lastly the Default Controller I want to access http://localhost/ciHrs/admin/ directly. thanks

I have a subfolder name admin on controller and subfolder name admin on view and subfolder admin on model

here is my routes

 <?php
defined('BASEPATH') OR exit('No direct script access allowed');

$route['admin/rooms'] = "admin/rooms/index";
$route['default_controller'] = 'admin/pages/view/dashboard';
$route['admin/(:any)'] = "admin/pages/view/$1";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

my Controller to access this page

<?php 

class Pages extends CI_Controller{
    public function view(){
        $data['title'] = 'Dashboard';

        $this->load->view('admin/templates/header');
        $this->load->view('admin/pages/dashboard',$data);
        $this->load->view('admin/templates/footer');
    }
}

I think you are not relying to CI uri routing

EXPLAINING

On your routes:

$route['admin/rooms'] = "admin/rooms/index";

So here, you can call the domain and the corresponding admin/rooms depends on your $route definition. It looks like this: http://example.com/admin/rooms instead of http://example.com/admin/rooms/index

The default_controller seems to be loaded when the cookie session was set. You can only call the domain itself and it will load automatically the default_controller that you set.

Hence, on your question you said that you only want to get http://localhost/ciHrs/admin/ , why not define in on $route just like this:

$route['ciHrs/admin/'] = "ciHrs/admin/pages";

or considering if the pages uri is dynamic set your route to:

$route['ciHrs/admin/(:any)'] = "ciHrs/admin/$1";

Hope this helps!

Try the following rules on your routes :

defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'admin/pages/view/dashboard';
$route['admin'] = "admin/pages";
$route['admin/'] = "admin/pages";
$route['admin/rooms'] = "admin/rooms/index";
$route['admin/(:any)'] = "admin/pages/view/$1";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM