0

With GII I have created a list of records. I use the admin view so they are in a table view. On top of the table it is the search with a status for the records. When the status dropdown is changed I submit the form and the table gets searched. I want the default view of the admin to show only the active records so I want to create a link in the menu to this: medium/admin/?Medium[status]=active The actual link of course is medium/admin/?Medium%5Bstatus%5D=active

I have tried to do it with:

CHtml::link('Mediums', array("medium/admin", array('Medium[status]' => 'active')))
CHtml::link('Mediums', array("medium/admin", array('Medium%5Bstatus%5D' => 'active'))) 
CHtml::link('Mediums', array("medium/admin", array('Medium' => array('status' => 'active')))) 

But all of the links are incorrect so the default view of the table is with all the records shown.

What is the correct way to create such a link?

Thank you.

Mihai P.
  • 9,307
  • 3
  • 38
  • 49

1 Answers1

0

http://www.yiiframework.com/doc/api/1.1/CHtml#link-detail and http://www.yiiframework.com/wiki/48/ will be usefull for you.

CHtml::link(CHtml::encode('Mediums'),array("medium/admin", "status"=>"active"));

Then ensure that in your controller you have something like this:

public function actionAdmin($status)

Now you ca use 'status' in your action.

ineersa
  • 3,445
  • 30
  • 40
  • Thank you but I do not want a variable called status, I want one called Medium[status]. – Mihai P. Apr 22 '13 at 23:20
  • Status is not variable its a field of model `Medium`. To pass parameters via `CHtml::link()` you need to accept them in your propper action in controller. Right like i typed above. `public function actionYourActionInControler($status)` then you can make smthing like this if you using ActiveRecord `$model=Medium::model()->findAll('status=:status', array(':status'=>$status));` Now `$model` will contain all your records with `$status` given link parameters. Now pass this `$model` to your view `$this->render('admin',array( 'model'=>$model,));`. Use it your view and be happy. – ineersa Apr 23 '13 at 07:58
  • You are partially right. Status is both column and a variable for both the model and the controller. I can of course do exactly that but you tell me to do but I do not want that. I want to keep my Yii application as close to the demos as I can. In their own examples Yii names the search fields with "Post[status]". That is exactly how I am naming them too. I just want to be able to transmit it as a GET variable using the internal yii CHTML::link() function. – Mihai P. Apr 24 '13 at 10:34
  • Then do it like this. http://www.yiiframework.com/forum/index.php/topic/3087-solved-getting-variables-past-from-url/ – ineersa Apr 24 '13 at 12:00
  • I can get the parameter from the GET in the URL, I cannot create an URL how I need it. – Mihai P. Apr 24 '13 at 13:35