php - CakePhp - how to access variables inside find->innerJoinWith? -
this question has answer here:
- php variables in anonymous functions 1 answer
i trying query users assigned project in cakephp. how achieve this:
$projectid = //project id query result. $users = $this->tickets->users ->find('list', ['limit' => 200]) ->innerjoinwith( 'projectsusers', function($q){ return $q->where(['projectsusers.project_id' => $projectid]); } );
this code works when not using variables (eg. replacing $projectid 8) when try use variables get: undefined variable: projectid
how can pass variables innerjoinwith?
if mean how inherit variable parent scope, you'd this.
$users = $this->tickets->users ->find('list', ['limit' => 200]) ->innerjoinwith( 'projectsusers', function($q) use($variabletopass) { return $q->where(['projectsusers.project_id' => $variabletopass]); } );
Comments
Post a Comment