用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4892|回复: 4
收起左侧

[HELP] 路由问题

[复制链接]
发表于 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的话就没有错误,请问这是什么问题?

发表于 2011-6-20 10:28:12 | 显示全部楼层
class Index extends ,Index是保留字
详情:
http://codeigniter.org.cn/user_guide/general/reserved_names.html
 楼主| 发表于 2011-6-20 10:31:01 | 显示全部楼层
但是我下载别人的作品这样写是可以的,莫非在其他地方做了手脚?
发表于 2011-6-20 10:35:05 | 显示全部楼层
gxseanjiang 发表于 2011-6-20 10:31
但是我下载别人的作品这样写是可以的,莫非在其他地方做了手脚?

没,你要加个
function __construct()
{
      parent::__construct();
}
 楼主| 发表于 2011-6-20 10:40:37 | 显示全部楼层
谢谢指教!!

本版积分规则