Multi-module MVC framework in phalconphp

Hi, I am trying to implement a multi-module MVC for the interface and backend, like what is in the phalconphp documentation , but I can not get it to work. it's about an hour, but I really can't figure out where the problem is.

Can someone guide me how can I make a skeleton for mvc multimodule for interface and backend.

what should I add to Moudle.php for the interface and backend
And also what should I put in the bootstrap file located in public / index.php
And any additional file or information that I need.

Thanks for the advanced.

+4
source share
1 answer

phalcon/mvc GitHub . : https://github.com/phalcon/mvc/tree/master/multiple

, :

https://github.com/phalcon/mvc/blob/master/multiple/public/index.php https://github.com/phalcon/mvc/blob/master/multiple/apps/backend/Module.php

index.php:

$application = new \Phalcon\Mvc\Application($di);

// Register the installed modules
$application->registerModules(
    array(
        'web' => array(
            'className' => 'Apps\Web\Module',
            'path'      => '../apps/web/Module.php',
        )
    )
);

echo $application->handle()->getContent();

Module.php:

<?php

namespace Apps\Web;

use Phalcon\Loader;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
use Phalcon\Mvc\ModuleDefinitionInterface;

class Module implements ModuleDefinitionInterface
{

    /**
     * Register a specific autoloader for the module
     */
    public function registerAutoloaders()
    {

        $loader = new Loader();

        $loader->registerNamespaces(
            array(
                'Apps\Web\Controllers' => '../apps/web/controllers/',
            )
        );

        $loader->register();
    }

    /**
     * Register specific services for the module
     * @param \Phalcon\DI\FactoryDefault $di
     */
    public function registerServices($di)
    {
        //Registering a dispatcher
        $di->set(
            'dispatcher',
            function() use ($di) {
                $eventsManager = $di->getShared('eventsManager');
                $dispatcher = new Dispatcher();
                $dispatcher->setDefaultNamespace('Apps\Web\Controllers');
                $eventsManager->attach(
                    'dispatch:beforeException',
                    function($event, $dispatcher, $exception) use ($di) {
                        /* @var $dispatcher \Phalcon\Mvc\Dispatcher */
                        switch ($exception->getCode()) {
                            case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                            case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                                $di->set('lastException', $exception);
                                $dispatcher->forward(
                                    array(
                                        'module' => 'web',
                                        'controller' => 'error',
                                        'action' => 'notFound',
                                    )
                                );
                                return false;
                            default:
                                $di->set('lastException', $exception);
                                $dispatcher->forward(
                                    array(
                                        'module' => 'web',
                                        'controller' => 'error',
                                        'action' => 'uncaughtException',
                                    )
                                );
                                return false;
                        }
                    }
                );
                $dispatcher->setEventsManager($eventsManager);
                return $dispatcher;
            }
        );
    }

}

, !

+6

Source: https://habr.com/ru/post/1537294/


All Articles