Yii 框架模块通过 URL 路由


Yii framework module routing through URL

我已经在 Yii 上开发了这个项目,问题是模块无法通过 URL 访问。所以,我去了我的/config/main.php 查看 URL 管理器代码。就像:

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

编辑:添加了'caseSensitive'=>false,

模块部分就像

'modules'=>array(
    'api_v1',   
    'api_s1',
),

在模块内部,我有两者的文件夹,它们再次具有控制器文件夹。控制器文件夹下的控制器是服务器控制器.php具有类似 操作列表

但是当我去访问这个模块时,我在浏览器中输入为:

http://domain-name/api_s1/server/List

但它显示404错误。我不确定还需要什么。任何帮助将不胜感激。

编辑:

我在每个主文件夹中都有一个.htaccess文件,如protectedframework和主文件夹中。所有.htaccess文件只有一行 全部拒绝表单

但是根目录上的主.htaccess文件有这个

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
ErrorDocument 404 /notfound.html

希望这对您有所帮助

'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>',
        ),
                array('api/controller/action/', 'api/controller/action', 'caseSensitive'=>false, 'verb'=>'GET'),
                )

尝试喜欢

http://domain-name/index.php/api_s1/server/List

希望你没有使用.htaccess coz,如果你使用的是.htaccess,你必须提到

"showScriptName" => false

config/main.php 中的urlManager中移除index.php

编辑:再次尝试将这些添加到您的urlManager

    '<module:'w+>/<controller:'w+>/<action:['w-]+>' => '<module>/<controller>/<action>',
    '<module:'w+>/<controller:'w+>' => '<module>/<controller>',
    '<module:'w+>' => '<module>',

请将此代码添加到您的.htaccess中,希望这可以帮助您

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/$1 [L,QSA]
enter code here
        .htaccess file should conatain(in Root folder of your project along with index.php)
        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

        In main.php
        urlManager'=>array("showScriptName" => false 
                            'caseSensitive'=>false,   
                            'showScriptName'=>false,
                                       ),
    Hope this helps.

   you have also mentioned you have more than one .htaccess files so to get more clarity also refer
    http://wordpress.stackexchange.com/questions/63114/two-htaccess-files-located-in-different-directories