如何不报错
在Controller中的代码(注意$id = null)
$list = $PeopleModel->getPeople($id = null);
报错提示
[8] Undefined variable: con E:\xampp\htdocs\guanli\Application\Admin\Model\PeopleModel.class.php 第 18 行.
模型代码
//第18行代码
return $result = $m->where($con)->select();
<?php
namespace Admin\Model;
use Think\Model;
class PeopleModel extends Model{
protected $_map = array(
'id' => 'people_id',
'name' => 'people_name',
'age' => 'people_age',
'idcard' => 'people_idcard',
);
public function getPeople($id){
$m = M('people');
if($id){
$con['people_id'] = $id;
}
return $result = $m->where($con)->select();
}
public function deletePeople($id){
$m = M('people');
$con['people_id'] = $id;
return $result = $m->where($con)->delete();
}
}
要怎么写 才可以不报错?
猴哥哥们要说清楚哦 不然可能不会被采纳呢!
参数
$con
要做初始化,不然你$id
不传的时候就没有$con
的定义了