如何在cakephp 3中的treeList自定义查找器中添加条件

时间:2017-01-02 13:52:42

标签: cakephp treeview cakephp-3.0

我正在使用TreeBehavior来使用自定义finder treeList自定义查找程序生成树结构

$this->Categories->find('treeList',['spacer' => '__']);

现在我如何添加"isactive" =>true等条件。我检查过的文档只有3个参数。无法找到条件参数

提前致谢

1 个答案:

答案 0 :(得分:2)

这不是一个“自定义”查找程序,更像是一个内置程序,因为它附带了CakePHP核心。

话虽这么说,条件可以像添加任何其他查找器一样添加,也就是说,通过传递给conditions方法的第二个参数的find()选项,或者通过查询建设者where()方法。

来自文档的引用:

  

启动查询后,您可以使用Query Builder界面   构建更复杂的查询,添加其他条件,限制或   包括使用流畅界面的关联。

// In a controller or table method.
$query = $articles->find('all')
    ->where(['Articles.created >' => new DateTime('-10 days')])
    ->contain(['Comments', 'Authors'])
    ->limit(10);
     

您还可以提供许多常用的find()选项。这个可以   帮助测试,因为模拟的方法较少:

// In a controller or table method.
$query = $articles->find('all', [
    'conditions' => ['Articles.created >' => new DateTime('-10 days')],
    'contain' => ['Authors', 'Comments'],
    'limit' => 10
]);

<强> Cookbook > Database Access & ORM > Retrieving Data & Results Sets > Using Finders to Load Data

相关问题