cakephp find_in_set

To perform a find_in_set operation in CakePHP, you can use the find() method along with the conditions parameter. The find() method allows you to retrieve records from a database table based on specific conditions.

To use find_in_set, you can pass the condition as an array to the conditions parameter. The condition should be in the format fieldname IN (values). Here's an example:

$this->ModelName->find('all', [
    'conditions' => [
        'find_in_set(fieldname, values)'
    ]
]);

Replace ModelName with the name of your model, fieldname with the name of the field you want to search in, and values with the comma-separated list of values you want to search for.

For example, if you have a users table with a roles field containing comma-separated values, and you want to find records where the roles field contains the value 'admin', you can use the following code:

$this->User->find('all', [
    'conditions' => [
        'find_in_set("admin", roles)'
    ]
]);

This will return all records where the roles field contains the value 'admin'. You can modify the condition and the field name as per your specific requirements.

Note that the find_in_set function is not a built-in CakePHP function, but rather a MySQL function. It allows you to search for a value within a comma-separated list.