controller里面load自定义的library,突然报错了
之前用得好好的在,郁闷。libraries/First.php
class First {
public function __construct() {
echo 111; //这里执行了的
}
public function test() {
echo 'test';
}
}
controller里面
$this->load->library('first');
$this->first->test(); //一直报错,Call to a member function test() on null
关键是以前都是对的,最近突然运行就报这个错,请教了。
你是不是有定义了一个 first 的成员变量 本帖最后由 michaelzhouh 于 2017-10-25 11:12 编辑
终于找到坑在哪里了。
类名我用的驼峰,我改成全小写就可以了。
比如上面那个类是First就可以,如果改成了FirstTest.php
$this->load->library('firstTest');
$this->firstTest->test();
这样就会报错,必须要写成
$this->load->library('firstTest');
$this->firsttest->test();
自从用了CI我超级讨厌驼峰命名! gogogo1027 发表于 2017-10-27 18:19
自从用了CI我超级讨厌驼峰命名!
CI 的命名需要大写开头
页:
[1]