【问题标题】:Is it possible to use default paths when I have enabled 'urlFormat'=>'path' in CUrlManager?当我在 CUrlManager 中启用 'urlFormat'=>'path' 时,是否可以使用默认路径?
【发布时间】:2013-06-12 09:19:19
【问题描述】:

你能解释一下这件事吗?如果我在 CUrlManager 中使用“路径”格式,标准路径会起作用吗?

例如,我在我的配置文件中启用了 CUrlManager 组件:

'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),

现在我可以使用这样的路径: http://example.com/controller/action?param1=value1&param2=value2...

它会起作用吗?: http://example.com/index.php?r=controller/action&param1=value1&param2=value2...

我需要使用旧路径来向后兼容一些外部程序。

【问题讨论】:

    标签: php yii


    【解决方案1】:

    不,默认情况下它不会工作,但是通过修改 index.php 文件,通常有一些肮脏的黑客可能使旧路径继续工作,就像提到的 here

    【讨论】:

      【解决方案2】:

      是的,很有可能

      试试这个

      打印 Yii::app()->request->getParam("param2");exit;

      如果有任何问题,请告诉我

      【讨论】:

      • 它对我有用,但我不确定 Yii 的行为是否正确?所以我问了。
      • 是的,它非常正确,其中一个好处是,如果您使用 getParam,您永远不会收到任何警告/异常,例如 $_POST['param1']。 :)
      猜你喜欢
      • 2022-11-10
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      相关资源
      最近更新 更多