在Kohana 2.3.4中默认加载模块然后加载控制器

时间:2022-10-13 15:33:21

Working in Kohana 2.3.4, I need to load a module when I go to example.com.

在Kohana 2.3.4中工作,我需要在访问example.com时加载模块。

In the routes.php file you can specify a default controller like:

在routes.php文件中,您可以指定默认控制器,如:

$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?

有没有办法默认加载模块,然后指定要在该模块中加载的默认控制器?

1 个解决方案

#1


0  

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.

在2.3.4中,您需要指定要在application / config / config.php中加载的模块。加载后,您可以像在标准控制器中一样在路由中使用它们。

Assuming within your module you had a controller named foo and a method named bar your default route would simply be:

假设你的模块中有一个名为foo的控制器和一个名为bar的方法,你的默认路由就是:

$config['_default'] = 'foo/bar';

Example config from http://docs.kohanaphp.com/general/modules

示例配置来自http://docs.kohanaphp.com/general/modules

// Paths are relative to the docroot, but absolute paths are also possible
// Use the MODPATH constant (?)
$config['modules'] = array
(
    MODPATH.'acl',
    MODPATH.'auth',
)

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.

值得注意的是Kohana文件系统是级联的,因此应用程序文件夹中的重复控制器(和其他文件)将覆盖模块控制器,而模块控制器又会覆盖系统控制器。

For more see: http://docs.kohanaphp.com/general/filesystem#cascading

有关详细信息,请参阅:http://docs.kohanaphp.com/general/filesystem#cascading

#1


0  

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.

在2.3.4中,您需要指定要在application / config / config.php中加载的模块。加载后,您可以像在标准控制器中一样在路由中使用它们。

Assuming within your module you had a controller named foo and a method named bar your default route would simply be:

假设你的模块中有一个名为foo的控制器和一个名为bar的方法,你的默认路由就是:

$config['_default'] = 'foo/bar';

Example config from http://docs.kohanaphp.com/general/modules

示例配置来自http://docs.kohanaphp.com/general/modules

// Paths are relative to the docroot, but absolute paths are also possible
// Use the MODPATH constant (?)
$config['modules'] = array
(
    MODPATH.'acl',
    MODPATH.'auth',
)

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.

值得注意的是Kohana文件系统是级联的,因此应用程序文件夹中的重复控制器(和其他文件)将覆盖模块控制器,而模块控制器又会覆盖系统控制器。

For more see: http://docs.kohanaphp.com/general/filesystem#cascading

有关详细信息,请参阅:http://docs.kohanaphp.com/general/filesystem#cascading