简体   繁体   English

带有SEO友好URL的PHP​​ MVC

[英]PHP MVC with SEO friendly URL

I know this, 我知道这个,

http://hostname/params1/params2

params1 represent model name and params2 represent action name. params1代表模型名称,params2代表动作名称。

But If i have a model class name like ReceivedRequest , how i convert all lowercase in params1(receivedrequest) to class name format? 但是,如果我有一个模型类名,如ReceivedRequest ,我如何将params1(receivedrequest)中的所有小写字母转换为类名格式? That case often happens during MVC development 这种情况通常发生在MVC开发期间

In Yii you can set the url rules caseSensitive option to false (the default is true) 在Yii中,您可以将网址规则caseSensitive选项设置为false(默认为true)

To do that, assuming the default controller/action rule, in your configuration: in your configuration: 为此,假设默认的控制器/操作规则在您的配置中:在您的配置中:

array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                '<controller:\w+>/<action:\w+>' => array('<controller>/<action>','caseSensitive'=>false),
            ),
        ),
    ),
);

And note, if you do that, that as a result you should follow the convention that you use lower case when specifying controller mapping (CWebApplication::controllerMap) and action mapping (CController::actions). 请注意,如果这样做,则应遵循在指定控制器映射(CWebApplication :: controllerMap)和动作映射(CController :: actions)时使用小写字母的约定。

Also, the directory names for organizing controllers should be in lower case. 另外,用于组织控制器的目录名称应为小写。

See http://www.yiiframework.com/doc/api/1.1/CUrlManager 参见http://www.yiiframework.com/doc/api/1.1/CUrlManager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM