开发者

CodeIgniter Default Controller

开发者 https://www.devze.com 2023-01-31 20:43 出处:网络
I am tring to create default controller for no matter what URL you access to. Meaning, custom 404. class MY_Exceptions extends CI_Exceptions

I am tring to create default controller for no matter what URL you access to.

Meaning, custom 404.

class MY_Exceptions extends CI_Exceptions
{
var $ci;

public function __construct()
{
    parent::CI_Exceptions();
    $this->ci =& get_instance();
}

function show_404($page = '')
{
  //load view here

}

}

I am getting get_instance is undefined. (because it was defined after the libraries get called)

Is there a way to create custom 404 controll开发者_如何转开发er in codeignigter 1.7.2 without playing with the system core code.

Thanks


Upgrade to CodeIgniter 2.0 because its stable and use:

$route['404_override'] = '';


If you just want to customize the 404 page, you can do so under the /system/application/errors/error_404.php page. The one caveat with this is that you can't use the $this object, it's strictly HTML/CSS or built-in PHP (no access to your libraries, models, etc.).

This is the page that CodeIgniter will display by default when it can't find a controller to handle a request.

Not sure if that's why you're trying to do or not, but that would be the simplest way to create a custom 404 page.


http://maestric.com/doc/php/codeigniter_404

i have used this solution and it works for me in CI 1.7


This should work fine. Make sure it's in the 'application/libraries' folder, and make sure your config has 'MY_' set as the custom library name.

Also, if you are doing function __construct(){}, you can do parent::__construct().

0

精彩评论

暂无评论...
验证码 换一张
取 消