I have created controller file in sub folder of controller on codeigniter 3.0.
i am using query string formate for url not segment .
i have two type of sub folder for backend(admin) and frontend(user).
i have also created MY_Router file in core folder of application folder.
Structure of Controller
Controller
--backend
---admin.php
---product.php
--frontend
---user.php
I want url for admin panel:
http://localhost/DemoSite/admin_panel/admin/dashboard
admin_panel want it in URL before every backend controller call
admin is Controller
dashboard is Function
For frontend :
http://localhost/DemoSite/user
I have done route like this :
$route['default_controller'] = 'frontend/user';
$route['admin_panel/(:any)'] = "backend/$1";
$route['(:any)'] = "user/$1";
MY_Router File Code:
<?php
class MY_Router extends CI_Router {
protected function _set_default_controller() {
if (empty($this->default_controller)) {
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
// Is the method being specified?
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
if (is_dir(APPPATH . 'controllers/' . $class)) {
$this->set_directory($class);
$class = $method;
if (sscanf($method, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
}
if (!file_exists(APPPATH . 'controllers/' . $this->directory . ucfirst($class) . '.php')) {
return;
}
$this->set_class($class);
$this->set_method($method);
// Assign routed segments, index starting from 1
$this->uri->rsegments = array(
1 => $class,
2 => $method,
);
log_message('debug', 'No URI present. Default controller set.');
}
}