Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 request parameter from url

Tags:

yii

yii2

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'); ?>
like image 468
davidndunoon Avatar asked Oct 16 '14 12:10

davidndunoon


2 Answers

You can use the following code in Yii2:

     Yii::$app->getRequest()->getQueryParam('companyAdd_id')
like image 177
Adam Fentosi Avatar answered Oct 19 '22 11:10

Adam Fentosi


<?= Yii::$app->request->get('companyAdd_id') ?>

like image 22
Ruben Avatar answered Oct 19 '22 10:10

Ruben