我在 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
中没有匹配的urlrules
。这是否意味着当 Yii 找不到任何匹配的 url 规则时,它就会开始寻找匹配的模块?
最佳答案
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>
看起来它从正常规则开始,然后继续尝试其他模块(及其 Controller /操作)。似乎使用模块 ID(在本例中为 gii)作为其第一部分。
进一步研究,是的,确实如此。请参阅Yii Module page了解更多信息。
关于php - Yii框架中定义的Gii的路由在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8622781/