cakeHP从带有条件的模型中获取数据(在特定日期之后)


cakePHP getting data from model with a condition (after specific date)

我想使用从get请求中获得的条件从数据库中获取信息。

型号

id | title | date

获取请求是:

$frutherthan = $this->request->query('furtherthan');

现在如何从日期大于$furtthan的模型中获取数据?

干杯

首先,您需要在控制器中创建查找并将$furtherthan变量传递给它。

$this->Model->find( 'list', array( 
    'conditions' => array( 
        'Model.date >=' => $furtherthan 
     ) 
) );

这将为符合条件的记录返回一个列表(id和显示字段)。您可能需要稍微更改实际的SQL,但这应该会让您开始。你可以在食谱中找到更多。

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-查找条件