Domanda

I am trying to learn Codeigniter. I am trying to use application/core/MY_Controller in my CI application. MY_Controller.php as:

class MY_Controller extends CI_Controller {

  protected $data = array();

  function __construct() {
    parent::__construct();
  }

  function render_page($view) {
    //do this to don't repeat in all controllers...
    $this->load->view('templates/header', $this->data);
    //menu_data must contain the structure of the menu...
    //you can populate it from database or helper

    $this->load->view($view, $this->data);
    $this->load->view('templates/footer', $this->data);
  }

}

Now I started to write home controller as :

class Home extends MY_Controller {
         function __construct() {
    parent::__construct();
  }

        public function view($page = 'home')
        {
         $this->load->helper('text');
            $data['records']= $this->services_model->getAll();
            if ( ! file_exists('application/views/pages/'.$page.'.php'))
            {
                // Whoops, we don't have a page for that!
                show_404();
            }

            $data['title'] = ucfirst($page); // Capitalize the first letter


            $this->load->view('pages/'.$page, $data);


        } 

My views folder as

+pages
  +home.php
+templates
  +footer.php
  +header.php. 

Here are my config and route files.

$config['base_url'] = 'http://localhost/~ytsejam/kirmiziblog/';
$config['index_page'] = 'index.php';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';

I get 404 page not found error . How can I change my application to work with MY_Controller ?

È stato utile?

Soluzione

I also had this problem with extending core classes. My problem was that is was working on my local server, but not on my production server. I was receiving the 404 error in production, and only on my controllers that used the class extensions. After some research I noticed that my local server was running php version 5.3.x, while my production server was running 5.2.x. To fix this I had to upgrade my production server to 5.3.

To find out what version of php your site is using, place this command in your view:

<?php echo phpversion() ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top