gxseanjiang 发表于 2011-6-20 10:12:53

路由问题

我在routes.php里面$route['default_controller'] = "index";
cntroller里面的index.php写
<?php
class Index extends CI_Controller {
    public function index()
    {
      $this->load->view('index/index');
    }
}
view里面都有对应的文件,访问时候就有下面错误:
A PHP Error was encounteredSeverity: Notice
Message:Undefined property: Index::$load
Filename: controllers/index.php
Line Number: 6


Fatal error:Call to a member function view() on a non-object in D:\Code\ci\a\controllers\index.php on line 6

如果都把对应的index改为home的话就没有错误,请问这是什么问题?

jeongee 发表于 2011-6-20 10:28:12

class Index extends ,Index是保留字
详情:
http://codeigniter.org.cn/user_guide/general/reserved_names.html

gxseanjiang 发表于 2011-6-20 10:31:01

但是我下载别人的作品这样写是可以的,莫非在其他地方做了手脚?

jeongee 发表于 2011-6-20 10:35:05

gxseanjiang 发表于 2011-6-20 10:31 static/image/common/back.gif
但是我下载别人的作品这样写是可以的,莫非在其他地方做了手脚?

没,你要加个
function __construct()
{
      parent::__construct();
}

gxseanjiang 发表于 2011-6-20 10:40:37

谢谢指教!!
页: [1]
查看完整版本: 路由问题