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

[版本 2.x] ci $this->load->view();报错

[复制链接]
发表于 2015-3-30 11:11:50 | 显示全部楼层 |阅读模式
本帖最后由 cimaster 于 2015-3-30 11:14 编辑

A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Index:load
Filename: controllers/index.php
Line Number: 8

NULLA PHP Error was encounteredSeverity: Notice
Message: Undefined property: Index:load
Filename: controllers/index.php
Line Number: 9


Fatal error: Call to a member function view() on a non-object in D:\WWW\ci-day01\CodeIgniter-2.2-stable\application\controllers\index.php on line 9
几天 出用 CI安装以后 看文档 研究了一下,调用了个视图 默认调用
控制器:welcome
方法:index
$this->load->view('welcome_message');
一点毛病没有
我将router文件里面的default welcome改成index
控制器:welcome
方法:index
$this->load->view('welcome_message');
出现报错

打印var_dump($thi->load);
是NULL

走默认控制器的默认方法的时候,有对象

object(CI_Loader)#12 (12) { ["_ci_ob_level":protected]=> int(1) ["_ci_view_paths":protected]=> array(1) { ["application/views/"]=> bool(true) } ["_ci_library_paths":protected]=> array(2) { [0]=> string(12) "application/" [1]=> string(46) "D:/WWW/ci-day01/CodeIgniter-2.2-stable/system/" } ["_ci_model_paths":protected]=> array(1) { [0]=> string(12) "application/" } ["_ci_helper_paths":protected]=> array(2) { [0]=> string(12) "application/" [1]=> string(46) "D:/WWW/ci-day01/CodeIgniter-2.2-stable/system/" } ["_base_classes":protected]=> &array(11) { ["benchmark"]=> string(9) "Benchmark" ["hooks"]=> string(5) "Hooks" ["config"]=> string(6) "Config" ["utf8"]=> string(4) "Utf8" ["uri"]=> string(3) "URI" ["router"]=> string(6) "Router" ["output"]=> string(6) "Output" ["security"]=> string(8) "Security" ["input"]=> string(5) "Input" ["lang"]=> string(4) "Lang" ["loader"]=> string(6) "Loader" } ["_ci_cached_vars":protected]=> array(0) { } ["_ci_classes":protected]=> array(0) { } ["_ci_loaded_files":protected]=> array(0) { } ["_ci_models":protected]=> array(0) { } ["_ci_helpers":protected]=> array(0) { } ["_ci_varmap":protected]=> array(2) { ["unit_test"]=> string(4) "unit" ["user_agent"]=> string(5) "agent" } }


请大侠指教 在线坐等。。。。。。








 楼主| 发表于 2015-3-30 13:50:59 | 显示全部楼层
自问 自答吧 文件的控制器名称 和方法名 不能一样
发表于 2015-3-30 11:23:35 | 显示全部楼层
我将router文件里面的default welcome改成index

這時候他會找一個名叫 index.php 的控制器文檔
发表于 2015-3-30 14:03:30 | 显示全部楼层
cimaster 发表于 2015-3-30 13:50
自问 自答吧 文件的控制器名称 和方法名 不能一样

不懂你的意思...沒影響吧
发表于 2016-6-19 09:19:40 | 显示全部楼层
cimaster 发表于 2015-3-30 13:50
**** 作者被禁止或删除 内容自动屏蔽 ****

的确,我昨晚也遇到这个问题,但是你知道为什么方法名和类名不能一样吗,是类本身的限制还是CI自己做了限制?
发表于 2016-6-19 10:08:38 | 显示全部楼层
uyuyuuy 发表于 2016-6-19 09:19
的确,我昨晚也遇到这个问题,但是你知道为什么方法名和类名不能一样吗,是类本身的限制还是CI自己做了限 ...

这是语法的问题。
方法名和类名一样的话,
这个方法就成了这个内的构造函数了。
发表于 2016-6-20 08:31:40 | 显示全部楼层
本帖最后由 wkang956 于 2019-9-25 16:43 编辑
uyuyuuy 发表于 2016-6-19 09:19
的确,我昨晚也遇到这个问题,但是你知道为什么方法名和类名不能一样吗,是类本身的限制还是CI自己做了限 ...

第三方三房撒范德萨
发表于 2016-6-20 09:49:59 | 显示全部楼层
原來如此,學習了!
发表于 2016-6-22 09:26:17 | 显示全部楼层
controllers/index.php
建议Index.php
Index类中还有index方法,此时ci会默认将index方法为构造方法

本版积分规则