Kohana 2.3.4 中默认加载模块,然后加载控制器
在 Kohana 2.3.4 中工作,当我访问 example.com 时,我需要加载一个模块。
在 routes.php 文件中,您可以指定一个默认控制器,例如:
$config['_default'] = 'welcome';
但它指的是主应用程序中的控制器。
有没有办法默认加载模块,然后指定要在该模块中加载的默认控制器?
Working in Kohana 2.3.4, I need to load a module when I go to example.com.
In the routes.php file you can specify a default controller like:
$config['_default'] = 'welcome';
but that refers to the controllers within the main application.
Is there a way to load a module by default, and then specify the default controller to load within that module?
在 2.3.4 中,您需要指定在
application/config/config.php
中加载哪些模块。一旦它们被加载,您就可以在路由中使用它们,就像使用标准控制器一样。假设在您的模块中您有一个名为 foo 的控制器和一个名为 bar 的方法,您的默认路由将很简单:
来自 的示例配置http://docs.kohanaphp.com/general/modules
值得注意的是,Kohana 文件系统是级联的,因此应用程序文件夹中的重复控制器(和其他文件)将覆盖模块控制器,而模块控制器又会覆盖系统控制器。
有关更多信息,请参阅:http://docs.kohanaphp.com/general/filesystem#cascading
In 2.3.4 you need to specify which modules you are loading in your
application/config/config.php
. Once they're loaded you can use them in your routing just as you would your standard controllers.Assuming within your module you had a controller named foo and a method named bar your default route would simply be:
Example config from http://docs.kohanaphp.com/general/modules
It's worth noting that the Kohana filesystem is cascading so duplicate controllers (and other files) in your application folder would override module controllers which in turn override the system controllers.
For more see: http://docs.kohanaphp.com/general/filesystem#cascading