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'); ?>

4 Answers 4

49

You can use the following code in Yii2:

     Yii::$app->getRequest()->getQueryParam('companyAdd_id')
Sign up to request clarification or add additional context in comments.

Comments

22

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

Comments

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

Comments

0

you can also use like this one.

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

2 Comments

Isn't this just the same as one of the other answers?
No It's different. You might be check it with previous answers..!! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.