简体   繁体   English

Phalcon多个模块不起作用

[英]Phalcon multiple module doesn't work

I want to work with multiple modules. 我想使用多个模块。 Therefore I created via phalcon command frontend and backend modules. 因此,我通过phalcon命令创建了frontendbackend模块。 To use this command phalcon module frontend I had to write a line in config.php 要使用此命令phalcon module frontend我必须在config.php写一行

'modulesDir'     => APP_PATH . '/app/modules/',

After use this command I started follow phalcon docs - according to this docs I had to register new modules by adding this code: (I put this in index.php ) 使用此命令后,我开始关注phalcon文档-根据该文档,我必须通过添加以下代码来注册新模块:(我将其放在index.php

$application->registerModules(
      array(
        'frontend' => function ($di) use ($view) {
          $di->setShared('view', function () use ($view) {
            $view->setViewsDir('../apps/frontend/views/');
            return $view;
          });
        },
        'backend' => function ($di) use ($view) {
          $di->setShared('view', function () use ($view) {
            $view->setViewsDir('../apps/backend/views/');
            return $view;
          });
        }
    )
);

After done this acctions I updated routes to default module - frontend . 完成此操作后,我将routes更新为默认模块- frontend

Finally after that I receive this notice: 最后,我收到此通知:

IndexController handler class cannot be loaded

In index controller I put namespace Application\\Frontend\\Controllers; 在索引控制器中,我放置了namespace Application\\Frontend\\Controllers;

What should I fix or improve to it works correctly? 我应如何解决或改进才能使其正常工作? Thanks in advance. 提前致谢。

Looks like you need update default routes. 看起来您需要更新默认路由。 Take a look at this code: 看一下这段代码:

$di->set('router', function () {

    $router = new Router(false);
    $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
    $router->removeExtraSlashes(true);

    $router->setDefaultModule('frontend');

    /**
     * Default routes
     */
    $router->add('/:module/:controller/:action/:params', [
        'module' => 1,
        'controller' => 2,
        'action' => 3,
        'params' => 4
    ]);
    $router->add('/:module/:controller', [
        'module' => 1,
        'controller' => 2,
        'action' => 'index'
    ]);
    $router->add('/:module', [
        'module' => 1,
        'controller' => 'index',
        'action' => 'index'
    ]);
    $router->add('/', [
        'action' => 'index',
        'controller' => 'index'
    ]);
});

Also check your loader: 还要检查您的装载机:

$loader->registerNamespaces(array(
    'Application\Modules' => $config->app->modulesDir,
));

And I think, your controllers namespace should be: 而且我认为,您的控制器名称空间应为:

namespace Application\Modules\Frontend\Controllers;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM