Yii框架中定义的Gii的路由在哪里?
我在 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 规则时,它就会开始寻找匹配的模块?
I created a Yii application in the webroot. I enabled the Gii module and modify the .htaccess to remove the index.php part in the url.
I also have the urlManager
component defined in the config/main.php configuration file.
'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>'
)
)
When I enter http://www.mydomain.com/gii
in the browser, I get redirected to http://www.mydomain.com/gii/default/login
.
Obviously, there is no matching url rules
in the urlManager
. Does this mean that when Yii cannot find any matching url rule, it will then start looking for a matching module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
bobo,是的,看起来 Yii 确实开始查找匹配的模块:
看起来它从正常规则开始,然后继续尝试其他模块(及其控制器/操作)。似乎使用模块 ID(在本例中为 gii)作为其第一部分。
进一步研究,是的,确实如此。请参阅 Yii 模块页面 了解更多信息。
bobo, yes, it does look like Yii starts looking through matching modules:
Looks like it starts with the normal rules and then moves on down to trying additional modules (and their controller/actions) after that. Seems to be using the module ID (gii in this case) as the first part of it all.
On further research, yes, that's the case. See the Yii Module page for more info.
你是什么意思?? Gii 是一个模块,URL 是正确的,您有默认值,因为 CWebModule 中的 defaultController 属性是“默认”,您可以扩展 Gii 并根据需要自定义它。
What you mean?? Gii is a module and the URL is right you have the default because the defaultController proprerty in CWebModule is 'default' you can extend Gii and customize it if you want.