【发布时间】:2015-09-23 02:59:58
【问题描述】:
如何使用 URL 中现有的模型参数创建指向 Yii 表单的 URL?
例如我有 $model 有一些属性,想得到这样的 URL:
controller/formaction?Form%5Battr1%5D=VAL1&Form%5Battr2%5D=VAL2
【问题讨论】:
如何使用 URL 中现有的模型参数创建指向 Yii 表单的 URL?
例如我有 $model 有一些属性,想得到这样的 URL:
controller/formaction?Form%5Battr1%5D=VAL1&Form%5Battr2%5D=VAL2
【问题讨论】:
您可以通过这种方式生成此类 URL:
Yii::app()->createUrl('controller/formaction', [
CHtml::activeName('Form', 'attr1') => 'VAL1',
CHtml::activeName('Form', 'attr2') => 'VAL2',
]);
【讨论】:
你有没有尝试过这样的事情:
public function action formaction(){
$form = Yii::app()->request->getQuery('Form',false);
}
【讨论】:
使用 GET 方法时无法自定义 url。当您使用 GET 方法时,browser 始终将所有输入的 name 和 value 与您的表单操作字符串连接起来。所以无法更改。摆脱丑陋网址的一种可能解决方案是使用 POST 而不是 GET。
【讨论】:
$model 中使用属性在另一个操作中创建表单的url。例如。当我使用 createUrl 函数 ($this->createUrl('formaction', $model)) 时,我得到如下结果:controller/formaction?attr1%5D=VAL1&attr2%5D=VAL2 并且在 formaction 中没有正确解析。