I'm working on this piece of code:
public function validateSelected($array = [1, 2])
{
$this->autoRender = false;
$samples = TableRegistry::get('Samples');
$samples->query()
->update()
->set(['validate' => true])
->where(function ($exp, $q) {
return $exp->in('id', $q);
})
->execute();
}
The code is pretty much self explanatory, I want to update all the rows with id's that would be passed in an array to the function.
I've tested the code by doing this:
->where(function ($exp, $q) {
return $exp->in('id', [1, 2, 3]);
})
And its working fine but i cant pass the passed array parameter to this where condition as it gives a syntax error undeclared variable $array.
Any idea about how can i achieve this thing would be great.