W
W
warcevil2016-12-01 13:18:14
Yii
warcevil, 2016-12-01 13:18:14

How to pass parameter to action in YII2?

How to pass parameter to action in YII2? It is also necessary to transfer through post.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2016-12-01
@qonand

How to pass or how to process a request from a Post? All this is described in detail in the documentation.

D
developer007, 2016-12-06
@developer007

print_r($_GET);
print_r($_POST);
look what will be there,
this is already the equivalent of \Yii::$app->request->post();

V
Vasily, 2016-12-14
@parazitl2

Например, данные поля из формы передаем методом post:
Форма во view-файле:

<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput() ?>   
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>        
<?php ActiveForm::end(); ?>

При нажатии на кнопку формируется POST, отлавливаем его в контроллере:
public function actionSomeAction()
    {
        $model = new SomeForm();

        if ($model->load(Yii::$app->request->post())) {
            ... делаем что нужно ...
        }

        return $this->render('someview', [
            'model' => $model,
        ]);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question