So basically, I would like to load a CodeIgniter controller contents outside CodeIgniter’s environment, that is, from a traditional PHP page.
I have tried the following but it doesn’t suit my requirements:
<?php require('/application/controller/error?type=not_found'); ?>
It gives the following error:
Message: require(/application/controller/error?type=not_found): failed to open stream: No such file or directory
To clarify, I’m trying to change the default /application/errors/error_404.php page contents to this so it will display the custom HTTP 404 error page I’ve built in the “error” controller & view.
The problem is, The pages under /application/errors/ are treated as normal PHP pages by CodeIgniter which means I can’t use
$this->load-view('error'); inside the
I would also appreciate other suggestions for ways to create custom error pages in CodeIgniter.
You should set the 404 page in the route.php page in the application/config folder:
$route['404_override'] = 'your-error-controller/your-error-view';
This route will tell the Router what URI segments to use if those provided in the URL cannot be matched to a valid route.
I might be confused at your question but the routes.php gives you a place where you can point the 404 page to a custom view.