I am setting up a CodeIgniter project and so far everything has been going well. All my routes and controllers are working correctly except for one. While I am new to CodeIgniter I have been programming in PHP for close to five years so I have a bit of experience. If anyone could take a look at the code samples below and let me know what I am doing wrong, that would be great.
Apparently the application does recognize the route, but it keeps complaining about its inability to find the URI.
Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profile extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function Profile($page = 'profile-page')
{
if ( ! file_exists(APPPATH.'/views/'.$page.'.php'))
{
// Load error page
show_404();
}
// Capitalize the first letter
$data['title'] = ucfirst($page);
$data['pageType'] = "profile-page";
// Load pages
$this->load->view('templates/header', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('profile');
$this->load->view('templates/footer', $data);
//
}
}
Next is my Routes:
$route['default_controller'] = 'home/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// All custom routes go below this line.
$route['contact'] = 'pages/contact';
$route['signup'] = 'auth/signup';
$route['login'] = 'auth/login';
$route['profile'] = 'profile/profile';
I have verified that all the view files are in their correct folders and there are no typos. However the Profile route keeps failing. All the other routes work correctly, except for the Profile route.
I have tried this on Windows 10 with XAMMP, Mac OS X Sierra with MAMP and CentOS 7 with Apache/PHP/MySQL.
Thanks.
The problem is your code enters into this condition & it is not able to find the profile-page.php file at that path and showing error.As profile function is calling properly without any issue as i checked
if ( ! file_exists(APPPATH.'/views/'.$page.'.php'))
{
echo "test";die;
// Load error page
show_404();
}