【问题标题】:Yii framework module routing through URLYii框架模块通过URL路由
【发布时间】:2015-02-05 23:32:31
【问题描述】:

我已经在 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'=&gt;false,

模块部分就像

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

在模块内部,我有两个文件夹,它们也有控制器文件夹。 controllers 文件夹下的控制器是 ServerController.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

【问题讨论】:

  • 尝试'caseSensitive' => false
  • 不,它也不起作用。我不确定,我错过了什么?我查了一下,到处都是这样。请看
  • 你有 .htaccess 吗?
  • 如果是,那么可能性就像你必须在 LINUX 中将 List 更改为 list,因为它区分大小写
  • 我还有其他一些不像 mostRating 那样有效的操作。所以同样适用于所有人?

标签: php yii url-rewriting module


【解决方案1】:
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

【讨论】:

    【解决方案2】:

    请将此代码添加到您的 .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]
    

    【讨论】:

      【解决方案3】:

      试试喜欢

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

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

      "showScriptName" => 假

      urlManager 中的config/main.php 中从您的网址中删除index.php

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

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

      【讨论】:

      • 感谢您的回复。我在主文件夹以及受保护和框架文件夹中有 .htaccess。更新的问题,请参阅编辑部分。
      【解决方案4】:

      希望对你有帮助

      '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'),
                      )
      

      【讨论】:

      • 感谢您的回复,但这也不起作用。似乎可能是因为 htaccess 文件。请参阅我编辑的问题。再次感谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      • 2015-10-23
      相关资源
      最近更新 更多