Phalcon多模块项目的默认模块是如何确定的?
情景
刚刚使用phalcon-dev-tools生成了一个phalcon的多模块程序,除了默认的frontend模块外,自己添加了other模块
情况描述
正常的通过www.test.com/frontend/test/test和www.test.com/other/test/test访问都没有问题
直接访问www.test.com/test/test走的是frontend的路由(我没有通过
$application->setDefaultModule
设置默认模块)
测试过程
我考虑可能是因为模块的注册顺序会影响默认情况,但是对调frontend和other模块的注册顺序结果仍然没有改变,依旧是走frontend的路由
当我使用
$application->setDefaultModule('other')
将other设置为默认模块的时候,仍然不起作用
问题总结
1.希望了解phalcon多模块的默认模块是怎么确定的
2.为什么当我使用setDefaultModule的时候仍然不起作用
3.\Phalcon\Mvc\Application
中的setDefaultModule和\Phalcon\Mvc\Router
中的setDefaultModule有什么不同
相关代码
测试代码只在默认的多模块应用中添加了other模块相关内容,代码如下
other模块的Module.php文件
<?php
namespace Multi\Other;
use Phalcon\DiInterface;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface
{
/**
* Registers an autoloader related to the module
*
* @param DiInterface $di
*/
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Multi\Other\Controllers' => __DIR__ . '/controllers/',
'Multi\Other\Models' => __DIR__ . '/models/',
));
$loader->register();
}
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Setting up the view component
*/
$di['view'] = function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
return $view;
};
}
}
模块注册文件
<?php
/**
* Register application modules
*/
$application->registerModules(array(
'other' => [
'className' => 'Multi\Other\Module',
'path' => __DIR__ . '/../apps/other/Module.php'
],
'frontend' => array(
'className' => 'Multi\Frontend\Module',
'path' => __DIR__ . '/../apps/frontend/Module.php'
),
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

被自己蠢哭了
答案就在默认的service.php中