A
A
akula222017-02-09 12:23:39
Yii
akula22, 2017-02-09 12:23:39

How to pass a parameter to the model?

Guys tell me how to pass a parameter to the model.
I am using himiklab\sortablegrid and the TourPlayoff model has this code

'sort' => [
                'class' => SortableGridBehavior::className(),
                'sortableAttribute' => 'position',
                'scope' => function ($query) {
                    $query->andWhere(['tour_id' => '? ']);
                },
            ],

I need to pass the tournament ID here, how to do this I can’t understand
such a code in the controller
public function actions()
    {
        return [      
            'sort' => [
                'class' => SortableGridAction::className(),
                'modelName' => TourPlayoff::className(),
            ],
        ];
    }

When ActionView is active, it also eats in the get Yii::$app->request->get('id')
and in the model $model = $this->findModel($id);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Derepko, 2017-02-09
@uDenX

andWhere
Most likely something like this:

'sort' => [
    'class' => SortableGridBehavior::className(),
    'sortableAttribute' => 'position',
    'scope' => function ($query) {
        $query->andWhere(['tour_id' => ':tour'], [':tour' => Yii::$app->request->get('id')]);
    },
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question