1

I'm total newbie on Yii. Professor basically asks us to make school project having shown us three things to do in Yii. Let's observe two classes I have, their models being: StudProg and NivoStudija. What I want is to pass attribute 'naziv' from nivoStudija/admin to studProg/admin, because when I click on a particular item nivoStudija/admin, studProg/admin is shown and I want to use this variable there. So I pass argument like this in one of my CGridView widget's items: CHtml::link($data->naziv, array("studProg/admin", "nivo_naziv" => $data->naziv))

It opens up studProg/admin and I see URL like this: http://localhost/pmf/index.php?r=studProg/admin&nivo_naziv=Osnovne+studije

My problem is: How do I get this nivo_naziv thing to use it in studProg/admin ? Thanks in advance.

3 Answers 3

1

For Yii1 you need the equivalent code

$my_nivo_naziv = Yii::app()->request->getQuery('nivo_naziv);
Sign up to request clarification or add additional context in comments.

Comments

0

I'm assuming that you are using Yii2.

Then you can get the URL parameter with:

 Yii::$app->getRequest()->getQueryParam('nivo_naziv');

Try this for Yii1:

Yii::app()->getRequest()->getParam('nivo_naziv');

5 Comments

I'm using yii 1.1.13 and it doesn't work. Any ideas how to do this? I saw something using actionAdmin and passing arguments but It didn't work or I didn't understand.
Could you provide more details? What is your route config? How looks your function?
You could always use $_GET, $_POST or $_REQUEST.
btw, @luka. saying it doesn't work is not helping you or anyone else. How do you know it does not work; what did you try; what results do you expect; what results do you get. Help us help you.
Thanks guys. I put the command where I was supposed to put the value I needed and it reported error. Could it be the problem that my string was made out of two words and had blank in between, cause that's what seems to get mentioned in an error? However, I edited code so I can't copy the error. Went crazy so I began all from the start and I solved passing some integer value but in another way. I passed the variable from Controller in actionAdmin method and retrieved it in my admin view. However, same thing didn't work for string with blank, and for one without gave other error. Makes no sense
0

In Yii if you want to access get and post parameter, you can use getParam function like this.

Yii::app()->request->getParam('nivo_naziv);

http://www.yiiframework.com/doc/api/1.1/CHttpRequest

Comments

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.