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

初学遇问题,不解

[复制链接]
发表于 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
 楼主| 发表于 2008-7-31 09:54:14 | 显示全部楼层
为什么去了构造函数就正常,加上就出错?
发表于 2008-7-31 09:55:44 | 显示全部楼层
~~~~~~~~~~~~~~~
 楼主| 发表于 2008-7-31 09:57:27 | 显示全部楼层
仿教程写的http://codeigniter.org.cn/forums/thread-3-1-1.html
为什么去了构造函数就正常,加上就出错?
 楼主| 发表于 2008-7-31 10:06:15 | 显示全部楼层
笔记:
火炬(280485704) 10:24:48
加這個到構造器parent::__construct();

Hex: 注意: CI 是用于 PHP4 的,所以,构造函数和类名同名。
发表于 2008-7-31 10:06:36 | 显示全部楼层
构造函数缺少 parent::Controller();
发表于 2008-8-1 23:23:04 | 显示全部楼层
如果要子类的构造函数要覆盖父类的,记得调用父类的构造函数(除非你不想用父类提供的某些功能)
parent::Controller();
这句代码将使你在子类的其它地方使用
$this->load->blablaba...
$this->db->hahahahaa
等等
发表于 2011-11-26 21:19:18 | 显示全部楼层
构造函数问题,呵呵,

function __construct()
{
  parent::__construct();
}
发表于 2011-11-26 21:24:07 | 显示全部楼层
哈哈,没有添加构造函数啊,我刚找到了,解决掉了
function __construct()
{
  parent::__construct();
}
发表于 2011-11-26 21:24:33 | 显示全部楼层
2008年的帖子,{:soso_e127:}

本版积分规则