首页 > Phalcon多模块项目的默认模块是如何确定的?

Phalcon多模块项目的默认模块是如何确定的?

情景

刚刚使用phalcon-dev-tools生成了一个phalcon的多模块程序,除了默认的frontend模块外,自己添加了other模块

情况描述

测试过程

问题总结

1.希望了解phalcon多模块的默认模块是怎么确定的
2.为什么当我使用setDefaultModule的时候仍然不起作用
3.\Phalcon\Mvc\Application中的setDefaultModule和\Phalcon\Mvc\Router中的setDefaultModule有什么不同

相关代码

测试代码只在默认的多模块应用中添加了other模块相关内容,代码如下

<?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'
    ),
));

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

/**
 * Registering a router
 */
$di->setShared('router', function () {
    $router = new Router();

    $router->setDefaultModule('other');
    $router->setDefaultNamespace('Multi\Other\Controllers');

    return $router;
});
【热门文章】
【热门文章】