Yii link with [ as a parameter

2019-08-16 09:19发布

问题:

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.

回答1:

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.