Redirect to show_404 in Codeigniter from a partial view Redirect to show_404 in Codeigniter from a partial view codeigniter codeigniter

Redirect to show_404 in Codeigniter from a partial view


You could throw an exception if there was an error in a submodule and catch this in your controller where you would do show_404() then.

Controller:

function profile($username){    try{       $out  = modules::run('user/details', $username);       $out .= modules::run('user/friends', $username);       echo $out;    }    catch(Exception $e){       show_404();    }}

Submodule:

function details($username){    $details = lookup_user($username);    if($details == 'User Not Found')        throw new Exception();    else        // Added third parameter as true to be able to return the data, instead of outputting it directly.        return $this->load->view('details', $details,true);}function friends($username){    $details = lookup_user($username);    if($friends == 'User Not Found')        throw new Exception();    else        return $this->load->view('friends', $friends,true);}


You can use this function to redirect 404 not found page.

    if ( ! file_exists('application/search/'.$page.'.php')) {        show_404(); // redirect to 404 page    }


its very simple , i solved the problem

please controler name's first letter must be capital e.g

A controller with

pages should be Pages

and also save cotroler file with same name Pages.php not pages.php also same for model class

enjoy