Welcome Guest, Not a member yet? Register   Sign In
CI 2.0 HOW TO make custom error_general.php (similar to 404_override)
#1

[eluser]Ki[/eluser]
I have a help section, which has about 10 sub sections, such as about, FAQ, etc. Instead of creating a method for every page, I just pass them to index page with _remap and then load them based on the $page variable. So /home/contact_us will go to Home controller, index method and "contact_us" is passed as variable $page. This allows me to change, add, remove help pages without writing/deleting methods for each. But I discovered that if user types in /home/contact_ussssss, it will throw the tragically unpleasant

Code:
An Error Was Encountered

Unable to load the requested file: content/help/contact_ussssss_view.php

1) Is there a way to customize this, similar to 404?
2) Any way to check if $this->load->view('content/help/'.$page.'_view', $this->data, TRUE) returns FALSE?
I have tried:

Code:
if($this->data['content'] = $this->load->view('content/help/'.$page.'_view', $this->data, TRUE)){
   // do nothing
}
else{
   $this->data['content'] = $this->load->view('content/help/help_main_view', $this->data, TRUE);
            }
#2

[eluser]WanWizard[/eluser]
This kind of error messages is produced by the show_error() function.

This function calls the show_error() method of the Exceptions library, so you can override this method and capture the call. However, since show_error() is not expected to return, that doesn't give you a return value to work with.

You could try checking if the view exists before loading it. $this->load->view() uses this code:
Code:
// $_ci_view is the name of the view file to load
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
$_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
$_ci_path = $this->_ci_view_path.$_ci_file;
if ( ! file_exists($_ci_path))
{
    show_error('Unable to load the requested file: '.$_ci_file);
}
#3

[eluser]Ki[/eluser]
Thank you!
Maybe a good feature request - I have seen a similar issue before. Good for developers who work with dynamic views.




Theme © iAndrew 2016 - Forum software by © MyBB