nexteee 发表于 2008-7-31 09:53:01

初学遇问题,不解

http://www.zhuxiaosheng.cn/www/ci/index.php/blog/comment/phil/24
<?php
class blog extends Controller{
function __construct(){
echo "haha<hr>";

}
function index(){
echo "我靠!这就是ci";


}
function comment($name,$age){

$data=array('name'=>$name,
      'age'=>$age);
$this->load->view('v_blog',$data);

}

}
?>
------------------------------------------
haha
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: blog::$load
Filename: controllers/blog.php
Line Number: 16


Fatal error: Call to a member function view() on a non-object in /home/acruxcn/public_html/zxs/www/ci/system/application/controllers/blog.php on line 16

nexteee 发表于 2008-7-31 09:54:14

为什么去了构造函数就正常,加上就出错?

lxccai 发表于 2008-7-31 09:55:44

~~~~~~~~~~~~~~~

nexteee 发表于 2008-7-31 09:57:27

仿教程写的http://codeigniter.org.cn/forums/thread-3-1-1.html
为什么去了构造函数就正常,加上就出错?

nexteee 发表于 2008-7-31 10:06:15

笔记:
火炬(280485704) 10:24:48
加這個到構造器parent::__construct();

Hex: 注意: CI 是用于 PHP4 的,所以,构造函数和类名同名。

Hex 发表于 2008-7-31 10:06:36

构造函数缺少 parent::Controller();

doutu 发表于 2008-8-1 23:23:04

如果要子类的构造函数要覆盖父类的,记得调用父类的构造函数(除非你不想用父类提供的某些功能)
parent::Controller();
这句代码将使你在子类的其它地方使用
$this->load->blablaba...
$this->db->hahahahaa
等等

ihwt@live.cn 发表于 2011-11-26 21:19:18

构造函数问题,呵呵,

function __construct()
{
parent::__construct();
}

ihwt@live.cn 发表于 2011-11-26 21:24:07

哈哈,没有添加构造函数啊,我刚找到了,解决掉了
function __construct()
{
parent::__construct();
}

ihwt@live.cn 发表于 2011-11-26 21:24:33

2008年的帖子,{:soso_e127:}
页: [1] 2
查看完整版本: 初学遇问题,不解