如何在 Codeigniter 4 模型中设置条件
How to put condition in Codeigniter 4 model
我在 Codeigniter 4 中有这个模型。
class CommentsModel extends Model
{
protected $table = 'comments';
protected $allowedFields = ['com_user', 'com_email', 'com_phone', 'comment'];
}
和这条路线
public function comments()
{
$model = new CommentsModel();
$data = [
'comments' => $model->paginate(50),
'pager' => $model->pager
];
echo view('templates/header');
echo view('templates/aside');
return view('comments', $data);
echo view('templates/footer');
}
我想把条件放在 WHERE 这样只会得到符合条件的评论....请帮忙!
在活动记录中使用 Where
子句来获得您想要的内容。
public function comments()
{
$model = new CommentsModel();
$model = $model->where('com_user','john');
$data = [
'comments' => $model->paginate(50),
'pager' => $model->pager
];
echo view('templates/header');
echo view('templates/aside');
return view('comments', $data);
echo view('templates/footer');
}
我在 Codeigniter 4 中有这个模型。
class CommentsModel extends Model
{
protected $table = 'comments';
protected $allowedFields = ['com_user', 'com_email', 'com_phone', 'comment'];
}
和这条路线
public function comments()
{
$model = new CommentsModel();
$data = [
'comments' => $model->paginate(50),
'pager' => $model->pager
];
echo view('templates/header');
echo view('templates/aside');
return view('comments', $data);
echo view('templates/footer');
}
我想把条件放在 WHERE 这样只会得到符合条件的评论....请帮忙!
在活动记录中使用 Where
子句来获得您想要的内容。
public function comments()
{
$model = new CommentsModel();
$model = $model->where('com_user','john');
$data = [
'comments' => $model->paginate(50),
'pager' => $model->pager
];
echo view('templates/header');
echo view('templates/aside');
return view('comments', $data);
echo view('templates/footer');
}