Hi!, in your index:
$application->registerModules(
array(
'public' => array(
'className' => 'Frontend\Module',
'path' => '../app/frontend/Module.php'
),
'private' => array(
'className' => 'Backend\Module',
'path' => '../app/backend/Module.php'
),
'common' => array(
'className' => 'Common\Module',
'path' => '../app/common/Module.php'
)
)
);
$response = $application->handle()->getContent();
after, create a file called Module.php
into the folder for the module, example:
app/common/Module.php
app/frontend/Module.php
app/backend/Module.php
and in every Module define:
<?php
namespace Frontend;
use Phalcon\Mvc\Dispatcher,
Phalcon\Mvc\View,
Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface {
/**
* Register a specific autoloader for the module
*/
public function registerAutoloaders(\Phalcon\DiInterface $di = null) {
}
/**
* Register specific services for the module
*/
public function registerServices(\Phalcon\DiInterface $di) {
//Registering a dispatcher
$di->set('dispatcher', function () use ($di) {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Frontend\Controllers");
// $dispatcher->setEventsManager($di->get('eventsManager'));
return $dispatcher;
});
//Registering the view component
$di->set('view', function() {
$view = new View();
$view->setViewsDir(APP_PATH.'app/frontend/views/');
$view->registerEngines(array('.volt' => 'voltService'));
return $view;
});
}
}
don't forget, change, the namespace's name, reference name.
you folder app:
app/frontend
controllers
views
app/backend
controllers
views
models
, etc...
and in your route:
something like:
$di->set('router', function () {
$router = new Router(false);
$router->setDefaultModule("backend");
$router->setDefaultAction('index');
$router->notFound(array(
'module' => 'common',
'controller' => 'error',
'action' => 'index',
'params' => '0404'
));
$router->add('/', array(
'module' => 'public',
'controller' => 'login',
'action' => 'index',
));
$router->add('/:module/:controller', array(
'module' => 1,
'controller' => 2,
'action' => 'index',
));
$router->add('/:module/:controller/([a-z]+)\.(json|html)/:params', array(
'module' => 1,
'controller' => 2,
'action' => 3,
'type' => 4,
'params' => 5
));
$router->add('/:module/:controller/([a-z]+)\.(json|html)', array(
'module' => 1,
'controller' => 2,
'action' => 3
));
return $router;
});
Try!, ;)