以 [ 作为参数的 Yii 链接 [英] Yii link with [ as a parameter

查看:11
本文介绍了以 [ 作为参数的 Yii 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 GII 创建了一个记录列表.我使用管理视图,因此它们位于表视图中.在表格的顶部是带有记录状态的搜索.当状态下拉列表更改时,我提交表单并搜索表格.我希望管理员的默认视图只显示活动记录,所以我想在菜单中创建一个链接:中/管理员/?中[状态]=活动实际链接当然是medium/admin/?Medium%5Bstatus%5D=active

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

我尝试这样做:

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?

谢谢.

推荐答案

http://www.yiiframework.com/doc/api/1.1/CHtml#link-detailhttp://www.yiiframework.com/wiki/48/ 对你很有用.

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)

现在您可以在操作中使用 'status'.

Now you ca use 'status' in your action.

这篇关于以 [ 作为参数的 Yii 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆