ci 2.0.2 怎么用?
本帖最后由 cherubimny 于 2011-6-21 18:10 编辑在model里,这句代码 $q = $this->db->get('user'); 报错了。
报错内容
“
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Bill::$db
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function get() on a non-object in D:\xampp\htdocs\newgame\application\models\user_model.php on line 10
”
上面的 “on line 10” 就是指 “$q = $this->db->get('user');”这句代码。
麻烦有人能帮我解答下么?谢谢~ 加载db了没?
model的构造函数写parent::__construct()了没?
新手好好看看手册啊,不要盲目的就去写程序,先了解下比较好 <?php
class Admin_user_model extends CI_Model{
function __construct(){
parent::CI_Model();
}
function check(){
$this->db->where('username',$this->input->post('username'));
$this->db->where('password', $this->input->post('password'));
$q = $this->db->get('user');
echo print_r($q);
if($q->num_rows() > 0){
echo 'OKOKOKO!';
}else {
echo '注册去';
}
}
}
我写了构造函数之后,页面访问出问题了,变成空白页面了。
function __construct(){
parent::__construct();
}
构造函数是这样写的
页:
[1]