【问题标题】:Yii Url Manager(replace post_id with post_name)Yii 网址管理器(将 post_id 替换为 post_name)
【发布时间】:2013-12-17 17:48:53
【问题描述】:

我已经在 Yii 中完成了一个网站。但问题是网站 url 对 SEO 不友好,并且在谷歌搜索中找不到它的位置。我的 url 为 http://helll.com/Industries?id=1

我想将我的网址更改为http://helll.com/Industries/hospitality-and-tourism,即用帖子名称替换帖子ID,我已经有这样的网址重写

'/Industries'=>'/lriIndustries/See',

like here What will be URL rewrite in yii url manager 我已经将我的 url 改写如下,但它似乎不起作用

'/Industries-<industries_name:.+>'=>'/lriIndustries/See',
echo $_GET['industries_name'];

【问题讨论】:

    标签: php yii url-rewriting yii-url-manager


    【解决方案1】:

    您忘记了 Industries 和 Industries_name 之间的斜线。

    '/Industries/<industries_name:.+>'=>'/lriIndustries/See',
    

    您还必须在 lriIndustriesController 中使用 urlFormat =&gt; 'path' 和 actionSee($industries_name) 启用 urlMangager 才能完成这项工作。

    你为什么到处回显 $_GET['industries_name'] ?您不发送任何 GET 变量。您的 $industries_name 变量必须像这样(在 lriIndustriesController 中)传递给 actionSee。

    public function actionSee($industries_name)
    {
        //find Industry by name and show it
    }
    

    【讨论】:

    • @VG 我有我的 main.php 代码 pastebin.com/uRSLjK8k 在此处查看文件 http://pastebin.com/y8CTDStw 因为它显示了一些错误,请您查看代码并帮助我谢谢你
    • @VG 是的,有一些错误注意:未定义的索引:第 3 行 /Applications/XAMPP/xamppfiles/htdocs/LRI-Original/protected/config/main.php 中的行业名称,这是我的控制器pastebin.com/wbGhz6Zx
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多