2

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

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

'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.

显然,rulesurlManager. 这是否意味着当 Yii 找不到任何匹配的 url 规则时,它会开始寻找匹配的模块?

4

2 回答 2

4

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 模块页面

于 2011-12-28T15:53:38.000 回答
0

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

于 2011-12-27T18:10:02.317 回答