Im learning CodeIgniter, thus I am still very new to the platform. I have the following problem:
I created a controller named admin;
I then added the path inside the routes file as such:
$route[admin/dashboard] = 'admin/dashboard;
Controller
class Admin extends CI_Controller {
public function dashboard($page ='dashboard'){
if(!file_exists(APPPATH.'/views/pages/'.$page.'.php')){
echo 'error';
show_404();
}
//check if Admin
$data['isAdmin'] = $this->admin_model->isAdmin($this->session->userID);
var_dump($data['isAdmin']);
$data['title'] = $page;
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
routes.php
#ADMIN
$route['admin/dashboard'] = 'admin/dashboard'; //ROUTE FOR ADMIN DASHBOARD
#USERS
$route['users']= 'users';
$route['users/index'] = 'users/index';
$route['users/login'] ='users/login';
$route['users/dashboard'] ='users/dashboard';
$route['users/profile'] = 'users/profile';
$route['users/userpicks/(:any)'] = 'users/userpicks/$1';
#PAGES
$route['pages/index'] = 'pages/index';
$route['pages/user_data_submit'] = 'pages/user_data_submit';
$route['(:any)'] = 'pages/index/$1';
$route['default_controller'] = 'pages/index';
Views
admin
------- dashboard.php
Config.php
$config['base_url'] = 'http://mysite';
PROBLEM / QUESTION
When I try to access http://mysite/admin/dashboard I get a 404 error
Tracing the route gives the following problem which I find strange. Looking at the below I believe the problem is with the configuration of routes.php ...?
DEBUG - 2018-06-26 08:53:45 --> UTF-8 Support Enabled DEBUG -
2018-06-26 08:53:45 --> Client sent : dashboard DEBUG - 2018-06-26
08:53:45 --> Route found : (:any) --> pages/index/$1 DEBUG -
2018-06-26 08:53:45 --> Redirecting to : dashboard -->
pages/index/dashboard DEBUG - 2018-06-26 08:53:45 --> Global POST, GET
and COOKIE data sanitized DEBUG - 2018-06-26 08:53:45 --> Session:
"sess_save_path" is empty; using "session.save_path" value from
php.ini. ERROR - 2018-06-26 08:53:45 --> 404 Page Not Found:
By looking at the above http://mysite/admin/dashboard somehow gets redirected to
Route found : (:any) --> pages/index/$1 DEBUG
I find this strange as I have "hardcoded" the route and placed it at the very top of routes.php yet it doesn't get executed for some reason...?
Any input and / or help appreciated.
http://mysite/index.php/admin/dashboard?? - Abdulla Nilam$config['base_url'] = 'http://mysite;- Timothy Coetzee$route['(:any)'] = 'pages/index/$1';route - Abdulla Nilam$route['(:any)'] = 'pages/index/$1';route hits before$route['admin/dashboard'] = 'admin/dashboard'- Ivan Vartanyan