سؤال

A noob question here! I am trying to make an index.php controller to view my site's homepage. But whenever I try to load the controller, I get the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Index::$load

Filename: controllers/index.php

Line Number: 7

Here is my code:

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

class Index extends CI_Controller {

    public function index()
    {
        $this->load->view('view_index');
    }

}

/* End of file index.php */
/* Location: ./application/controllers/index.php */
هل كانت مفيدة؟

المحلول

Include a constructor to your controller:

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

نصائح أخرى

You cannot have a controller named Index, it is said in their documentation on reserved names.

Reserved Names : CodeIgniter User Guide

Best thing to have is a controller named Home with Home.php as the file name, then put in the configuration of the default controller to have home, like so:

$route['default_controller'] = 'home';
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top