2017-01-02 54 views
1

添加條件樹形列表自定義查找我使用TreeBehavior使用自定義查找樹形列表自定義查找如何在CakePHP中3

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

現在生成樹狀結構如何添加一些條件像"isactive" =>true。我檢查過的文檔只有3個參數。無法找到狀態PARAM提前

回答

2

這是少了「定製」取景器,更內置了一個

感謝,因爲它附帶CakePHP的核心。

這就是說,條件可以加入相同的方式與任何其他測距儀,即,或者經由傳遞給find()方法的第二個參數的conditions選項,或者通過查詢構建器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