L
L
Lakewake2011-10-12 19:29:25
CodeIgniter
Lakewake, 2011-10-12 19:29:25

Codeigniter, 404 in controller?

I encountered unusual CI behavior when customizing a 404 error :(
I use a simple template library:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {
    var $template_data = array();
    
    function set($name, $value)
    {
      $this->template_data[$name] = $value;
    }
  
    function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
    {               
      $this->CI =& get_instance();
      $this->set('contents', $this->CI->load->view($view, $view_data, TRUE));			
      return $this->CI->load->view($template, $this->template_data, $return);
    }
}

/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */

I wanted to change the 404th error, I created the controller error404.php class Error404,
in the index() method I call view error404:
$this->template->load('template', 'error404');

Added to routes.php:
$route['404_override'] = 'error404';
If you access a non-existent page like site.ru/asdasdasdgfg, then everything is displayed correctly, but if you access, say, site.ru/login/asdasdasdasd, where login is a controller,
then an error occurs
Message: Undefined property: Error404::$template
Filename: controllers/error404.php

Experimentally, I found out that in the second case, $this does not contain either the template or the other libraries that are registered in autoload.php. Load them manually in the index() method - similarly, they are not in print_r($this). As well as in:
$CI =& get_instance();
print_r($CI);

Can anyone tell me how the controller, in this case, login, will affect the error404 controller? There are no unusual manipulations in login, just displaying pages.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrspd, 2011-10-14
@mrspd

In error404 the controller in the constructor called the constructor of the parent class? parent::__construct()?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question