Yii2 request parameter from url

davidndunoon picture davidndunoon · Oct 16, 2014 · Viewed 54.4k times · Source

In YII I could request a parameter from url and populate a form field called companyAdd_id with the following code, trying to do the same in YII2 but getting errors, looking for advice on how to do the same in YII2. thanks

<?php echo $companyAdd_id = Yii::app()->request->getParam('companyAdd_id'); ?>

<?php echo $form->hiddenField($model, 'companyAdd_id', array(
        'type'  => 'text',
        'value' => $companyAdd_id
)); ?>

<?php echo $form->error($model, 'companyAdd_id'); ?>

Answer

Adam Fentosi picture Adam Fentosi · Oct 16, 2014

You can use the following code in Yii2:

     Yii::$app->getRequest()->getQueryParam('companyAdd_id')