As you know, CodeIgniter uses default URL routing of class/function/parameters
. The class is a controller, and the function to be invoked inside the controller class is the second part of the URL. However, the user can easily change the URL to anything he wants, and I want my application to be able to display a graceful error message if the user is trying to view a function that does not exist. I looked through the CodeIgniter documentation on controllers and it doesn't seem to be listed there, or maybe I missed it. Here is an example of what I am talking about.
<?php
class Users extends MY_Controller {
function index(){ //do something }
function something_else(){ //do something else }
}
My application is written cleanly and smartly so there will not ever be a link inside my application that leads to anything except these two functions. However, the user can easily change the URL to anything he wants, such as http://www.mysite.com/welcome/another_thing
. I do not have function another_thing
, so if the user changed the URL to something like that, PHP currently yields the following error message.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$session
Filename: core/MY_Controller.php
Line Number: 15
Fatal error: Call to a member function userdata() on a non-object in /home/diftx/public_html/dol/application/core/MY_Controller.php on line 15
I currently have it extending MY_Controller instead of CI_Controller which I'm not sure if has anything to do with it. I would think that the application should redirect to my default view for 404 errors which is not_found.php
however this is not happening.