0

I want to work with multiple modules. Therefore I created via phalcon command frontend and backend modules. To use this command phalcon module frontend I had to write a line in 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)

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

Finally after that I receive this notice:

IndexController handler class cannot be loaded

In index controller I putnamespace Application\Frontend\Controllers;

What should I fix or improve to it works correctly? Thanks in advance.

betty39johnson
  • 151
  • 1
  • 2
  • 12
  • What's the file name of IndexController? i mean indexController.php or IndexController.php it should be IndexController.php here is the repo which phalcon command tool grab for multi module mvc. have a look on registerModules function and Modules.php in every module https://github.com/phalcon/mvc/tree/master/multiple – M Ashraful A Mar 29 '16 at 11:54
  • Can u provide git sources to see where the issue could be? – Boris Delev Mar 31 '16 at 13:10
  • Otherwise I can use ready multiple modules but I use phalcon commands - everything should go well. Out of curiosity I want to get to know why it returns an error. – betty39johnson Apr 01 '16 at 06:32

1 Answers1

0

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;
Anton Pelykh
  • 2,274
  • 1
  • 18
  • 21