<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Index extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
当控制器名和方法名都为index 的时候就会报错
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Test::$load
Filename: controllers/test.php
Line Number: 11
Fatal error: Call to a member function view() on a non-object in /var/www/html/ci/application/controllers/test.php on line 11
所以尽量保证2者不一样
非要一样,需要调用父类的构造方法
<pre name="code" class="html"><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Index extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index()
{
$this->load->view('index');
}
}