php - CakePhp - how to access variables inside find->innerJoinWith? -


this question has answer here:

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -