Question

If we call a method abc() within a controller named Example. Suppose abc() is not present in Example controller.

In such cases i need to display a custom error message instead of


404 Page Not Found

The page you requested was not found.


for this particular controller only.

I know we can set custom error pages, but it applies to all controller. I need to use it with one controller only.

For Eg:

class Example extends CI_Controller
{
    function index()
    {
        echo "index page";
    }

    function xyz() 
    {
        echo "xyz page";
    }
}

if i call example/xyz it displays output as 'xyz page'

but if i call example/abc it show page not found error. (i need custom message for this controller only).

Thank You...

Était-ce utile?

La solution

You can do something similar to below. If the method exists call it otherwise display your own error message.

function _remap( $method )
{
    // $method contains the second segment of your URI
    if(method_exists($this, $method ) )     
    {
         $this->$method();
    }
    else
    {
         //your custom coding here
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top