How to pass variable into joinWith() anonymous function?

Hi, everyone!

I have a next query

$model = SubCategory::find()

        ->select('*')


        ->joinWith([


            'category' => function ($query) {


                $query->joinWith('surveyCategories')


                      ->andWhere(['survey_category.survey_id' => $var]);


            },


        ])


        ->where([


            'survey_category.survey_id' => $var,


        ])


        ->all();

So while joining "category" table with its function($query) I need to pass variable $var right there. Please, help me and clarify this moment.

Thanks.




'category' => function ($query) use ($var) {

  $query->joinWith('surveyCategories')

	->andWhere(['survey_category.survey_id' => $var]);

}



PHP anonymous functions

phtamas, thanx a lot! :)