【问题标题】:Where are the routes for Gii defined in Yii framework?Yii 框架中定义的 Gii 路由在哪里?
【发布时间】:2011-12-24 04:54:37
【问题描述】:

我在 webroot 中创建了一个 Yii 应用程序。我启用了 Gii 模块并修改了 .htaccess 以删除 url 中的 index.php 部分。

我还在 config/main.php 配置文件中定义了urlManager 组件。

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

当我在浏览器中输入http://www.mydomain.com/gii 时,我会被重定向到http://www.mydomain.com/gii/default/login

显然,urlManager 中没有匹配的 url rules。这是否意味着当 Yii 找不到任何匹配的 url 规则时,它会开始寻找匹配的模块?

【问题讨论】:

  • ¿有什么问题?... ¿有问题吗?重定向到mydomain.com/gii/default/login 出乎您的意料? ¿ 你的预期是什么?
  • @Alfredo Castañeda García 问题是,gii 是模块名称,default 是控制器名称,login 是操作。 gii/default/login 即使我没有与之匹配的规则模式仍然有效,这就是我感到奇怪的地方。

标签: php url-routing yii yii-components


【解决方案1】:

bobo,是的,看起来 Yii 确实开始查看匹配的模块:

yii/framework/gii/GiiModule.php, Line 43
* http://localhost/path/to/index.php?r=gii
*
* If your application is using path-format URLs with some customized URL rules, you may need to add
* the following URLs in your application configuration in order to access GiiModule:
* <pre>
* 'components'=>array(
*     'urlManager'=>array(
*         'urlFormat'=>'path',
*         'rules'=>array(
*             'gii'=>'gii',
*             'gii/<controller:\w+>'=>'gii/<controller>',
*             'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
*             ...other rules...
*         ),
*     )
* )
* </pre>

看起来它从正常规则开始,然后继续尝试其他模块(及其控制器/操作)。似乎使用模块 ID(在本例中为 gii)作为这一切的第一部分。

在进一步的研究中,是的,就是这样。请参阅Yii Module page 了解更多信息。

【讨论】:

  • 当然,很高兴为您提供帮助。直到我看到你的问题才真正考虑过它是如何工作的:-)
【解决方案2】:

什么意思?? Gii 是一个模块,并且 URL 是正确的,因为 CWebModule 中的 defaultController 属性是“默认”,所以你可以扩展 Gii 并根据需要自定义它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    相关资源
    最近更新 更多