joinWith() anonimous function second arg

Hi Folks,

I need to pass a second argument to the anonimous function used by the joinWith() method. I am trying to do this way:

$model = new Product();

$model->section_id = 1;


    	$listOptions = ArrayHelper::map(VariationOption::find()->joinWith([

        	'variation.sections' => function ($query, $model) { // need second argument here

            	$query->andWhere(['' => $model->section_id]); // need to use it here


    	])->all(), 'id', 'option', '');

That results:

PHP Warning – yii\base\ErrorException

Missing argument 2 for backend\controllers\ProductController::backend\controllers\{closure}()

Using just the $query argument and a hardcoded id inside the function works although.

Am I doing something wrong? Is there a way to achieve that?

Thanks in advance.

EDIT: ** Sorry about the typo in the title. **

Like that

function ($query) use ($model)

1 Like

It is just PHP! My fault!

Thank you so much Bizley!