gpt4 book ai didi

Cakephp 3 : How to give condition in get method?

转载 作者:行者123 更新时间:2023-12-02 15:24:07 25 4
gpt4 key购买 nike

我试图在 cakephp 3 get 方法中给出一个条件,其中数据将通过外部 ID 而不是主键获取。在这里,我尝试了以下代码:

$eventPasswordAll = $this->EventPasswordAll->get($id, [
'conditions' => ['event_id'=>$id],
'contain' => ['Events']
]);

但它根据 id(primary key) 显示数据,而不是 event_id。我如何在 get 方法中添加此条件,例如 where event_id=my get id

最佳答案

不要使用 get , 使用 find .根据CakePHP 3.0 Table API , get方法:

Returns a single record after finding it by its primary key, if no record is found this method throws an exception.

您需要使用 find :

$eventPasswordAll = $this->EventPasswordAll->find('all', [  // or 'first'
'conditions' => ['event_id' => $id],
'contain' => ['Events']
]);
// or
$eventPasswordAll = $this->EventPasswordAll->find()
->where(['event_id' => $id])
->contain(['Events']);

关于Cakephp 3 : How to give condition in get method?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com