Yii框架中定义的Gii的路由在哪里?

发布于 2024-12-22 20:29:07 字数 801 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哽咽笑 2024-12-29 20:29:07

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 模块页面 了解更多信息。

bobo, yes, it does look like Yii starts looking through matching modules:

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>

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.

琉璃繁缕 2024-12-29 20:29:07

你是什​​么意思?? 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文