【问题标题】:how can we hide param in url of yii framework?我们如何在 yii 框架的 url 中隐藏参数?
【发布时间】:2014-01-06 13:19:45
【问题描述】:

对不起,我是新手,我在 Yii 框架中使用友好的 url。索引页面还可以,但是当我输入参数进行编辑时,url 不友好。

索引页:http://localhost/news/news/index.html

编辑页面:http://localhost/news/news/edit/59.html

我们如何隐藏 id 参数并拥有这样的 url:

http://localhost/news/news/edit.html

这是 main.php 中的配置

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

非常感谢

【问题讨论】:

    标签: yii


    【解决方案1】:

    您必须将某种形式的标识符附加到 url 以表示唯一记录。如果您想取消 ID,请使用标题或文本来达到使 url SEO 友好的目的。如果您要走那条路线,则必须设置自定义 url 规则。 请参阅http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-15
      • 2020-02-09
      • 2018-07-08
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多