如何在 yii 框架中自动设置 url 友好 [英] how to setup url friendly in yii framework automatically

查看:34
本文介绍了如何在 yii 框架中自动设置 url 友好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚学习了 yii 框架并阅读了本教程关于 yii 如何设置 url

I just learning yii framework and read this tutorial about yii how to setup url

但我不知道,假设我有 10 个控制器,我应该在配置文件中一个一个地定义控制器吗?有没有更好的方法来为所有控制器设置 url 友好,例如 www.yoursite.com/yourController/yourAction/yourID?

but I have no idea, suppose i have 10 controllers, should I define one by one controllers in the config file ? is there a better way to setup url friendly like www.yoursite.com/yourController/yourAction/yourID for all controller ?

我认为 codeigniter 是自动完成的...... yii 怎么样?

I think codeigniter did that automatically ... how about yii ?

推荐答案

在/protected/config/main.php 添加..

In /protected/config/main.php add..

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName' => false,      
        ),
    ),

在您的网络根目录中添加一个 .htaccess..

In your web root an .htaccess..

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

这篇关于如何在 yii 框架中自动设置 url 友好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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