M
M
Michael2018-12-23 17:55:10
Yii
Michael, 2018-12-23 17:55:10

How to pass two parameters?

Hello everybody! Tell me how can I pass two parameters when switching to the view, in the code below I pass only one id parameter, and I also need to pass the contract_id parameter. Tell me how to do it right?

'add' => function ($url, $model, $key)
{
    if($model->parent_id == false){
       return Html::a('<span class="glyphicon glyphicon-plus"></span>', \yii\helpers\Url::to(['type/add', 'id' => $model->id]), ['data-id' => $model->id]);
   }

public function actionAdd()
{
    $model = new Type();
    $model->loadDefaultValues();
    $id = Yii::$app->request->get('id');
    $model->parent_id = $id;

    if ($model->load(Yii::$app->request->post()) && $model->save())
    {
        return $this->redirect(['index']);
    }
    else
    {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2018-12-23
@Bally

return Html::a('<span class="glyphicon glyphicon-plus"></span>',   ['/type/add', 'id' => $model->id, 'contact_id'=>$model->contract_id]  ]);

Note that if you need to pass an external variable then use
function ($url, $model, $key) use ($externalParam)
{
if($model->parent_id == false){
return Html::a('', ['/type/add', 'id' => $model->id, 'contact_id'=>$model->contract_id] ]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question