Dynamically create the $filterArgs array in CakePH

2019-08-07 19:40发布

Is it possible to dynamically create the $filterArgs array in CakePHP when using the search plugin?

My customers are able to create their own input fields (customer specific) and I want to make all of them searchable. But for this I have to map them in the $filterArgs array.

E.g.:

public $filterArgs = array(
    'input_filter' => array(
        'type' => 'subquery',
        'method' => 'findCustomerCustomFieldsByText',
        'field' => 'Customer.id',
        'encode' => true
    )
);

1条回答
做个烂人
2楼-- · 2019-08-07 20:14

Just add them conditionally as you need to the filterArgs array.

if ($someFieldIsPresentCheckHere) {
    $this->Model->filterArgs['someThing'] = [ /* settings go here */ ];
}
查看更多
登录 后发表回答