我有一个devices/index
页面,默认情况下我不想显示“乱序”设备,除非我标记了一个正确的复选框
所以我使用了 CakeDC 搜索插件 3,然后我编辑了
设备表
public $filterArgs = [
'include_out_of_order' => [
'type' => 'finder',
'finder' => 'outOfOrder',
'allowEmpty' => true
],
// ...
// lot of other filters
// ...
]
public function findOutOfOrder($query, array $options)
{
if(isset($options['include_out_of_order']) && $options['include_out_of_order'] == true)
return $query;
else
return $query->where(['Devices.device_status_id !=' => 2]); //status = 2 means the device is out of order
}
现在这在我index
看来有效,但它也适用于我使用搜索插件过滤记录的另外两个操作。
我希望这个特定的过滤器只在index
行动中应用,而所有其他过滤器应该在设备控制器的其他操作中工作
是否有另一种方法可以使用 cakeDC 插件来实现我想要做的事情,或者我应该index
在控制器内的操作中使用一些自定义代码?这很容易,但我想找到一个更干净的解决方案