27

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'); ?>
robsch
  • 9,358
  • 9
  • 63
  • 104
davidndunoon
  • 295
  • 1
  • 5
  • 10

4 Answers4

48

You can use the following code in Yii2:

     Yii::$app->getRequest()->getQueryParam('companyAdd_id')
Adam Fentosi
  • 1,198
  • 10
  • 10
22

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

Ruben
  • 8,956
  • 14
  • 63
  • 102
1
 Yii::$app->getRequest()->getQueryParam('companyAdd_id')
vishuB
  • 4,173
  • 5
  • 31
  • 49
0

you can also use like this one.

Yii::$app->request->getQueryParam('companyAdd_id');