We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Multimodule application always route to '/'

Hello! Trying to implement Phalcon Multimodule arc. Doing all just like it said in documentation, but I have the problem: my site don't want to show anything but IndexController/indexAction.

Any other route than '/' - class 'index' was not found on handler 'index'. What can be problem?

My Module:

<?php

namespace Multi\Frontend;

use Phalcon\Loader;
use Phalcon\Mvc\View\Simple as SimpleView;
use Phalcon\DiInterface;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Mvc\View\Engine\Volt;

class Module implements ModuleDefinitionInterface
{
    public function registerAutoLoaders(DiInterface $di = null)
    {
        $loader = new Loader();

        $loader->registerNamespaces(
            array(
                'Multi\Frontend\Controllers' => '../app/frontend/controllers/',
                'Multi\Frontend\Models' => '../app/frontend/models/'
            )
        );

        $loader->register();
    }

    public function registerServices(DiInterface $di)
    {
        $di->set('dispatcher', function() {
            $dispatcher = new Dispatcher();
            $dispatcher->setDefaultNamespace('Multi\Frontend\Controllers');
            return $dispatcher;
        });

        $di->set('view', function() {
            $view = new SimpleView();
            $view->setViewsDir('../app/frontend/views/');

            $view->registerEngines(
                array(
                    ".volt" => function($view, $di) {
                        $volt = new Volt($view, $di);
                        $volt->setOptions(
                            array(
                                'compiledPath' => '../storage/volt',
                                'compileAlways' => true
                            )
                        );
                        return $volt;
                    }
                )
            );
            return $view;
        });
    }
}

My index.php

<?php

use Phalcon\Mvc\Router;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Session\Adapter\Files as Session;

$di = new FactoryDefault();

$di->set('router', function() {
    $router = new Router();
    $router->setDefaultModule("frontend");

    $router->add('/login', 
        array(
            'module'     => 'frontend',
            'controller' => 'Index',
            'action'     => 'login'
        )
    );
    return $router;
});

$di->set('session', function () {
           $session = new Session();
           $session->start();
           return $session;
       }
);

try {
    $application = new Application($di);

    $application->registerModules(
        array(
            'frontend' => array(
                'className' => 'Multi\Frontend\Module',
                'path'      => '../app/frontend/Module.php'
            ),
            'backend'  => array(
                'className' => 'Multi\Backend\Module',
                'path'      => '../app/backend/Module.php'
            )
        )
    );
    $application->useImplicitView(false);
    echo $application->handle()->getContent();
} catch(\Exception $e) {
    echo $e->getMessage();
}

Thank you!



145.0k
Accepted
answer
edited Jun '16

So you are trying to access /login and it doesn't work ? Maybe it's some problem with your nginx or apache configuration ? Can you show us controller as well ? Also you sure paths are fine ?

So you are trying to access /login and it doesn't work ? Maybe it's some problem with your nginx or apache configuration ? Can you show us controller as well ? Also you sure paths are fine ?

Hello, Wojciech! You are absolutel right, there is something wit my home nginx configuration. Checked again on work - all works correct.

Anyway, thank you for help and sorry fo false alert! :)