我在 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'); }我想把条件放在哪里,这样只会得到符合条件的评论……请帮忙!
1 回答
万千封印
TA贡献1891条经验 获得超3个赞
在活动记录中使用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');
}
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消