Dynamically create the $filterArgs array in CakePH

2019-08-07 19:59发布

问题:

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:

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

if ($someFieldIsPresentCheckHere) {
    $this->Model->filterArgs['someThing'] = [ /* settings go here */ ];
}