Make the application modular to have a "main" and "backend" part.
This commit is contained in:
parent
884f721002
commit
e5b0e1fcfd
28 changed files with 112 additions and 7 deletions
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
application:
|
||||
modulesDir : ../app/modules/
|
||||
controllersDir : ../app/controllers/
|
||||
modelsDir : ../app/models/
|
||||
migrationsDir : ../app/migrations/
|
||||
viewsDir : ../app/views/
|
||||
viewsDir : ../app/views/_common/
|
||||
templateDir : ../app/templates/
|
||||
listenersDir : ../app/listeners/
|
||||
libraryDir : ../app/library/
|
||||
|
|
|
|||
|
|
@ -56,3 +56,8 @@ router:
|
|||
path:
|
||||
controller: api
|
||||
action: activationlink
|
||||
|
||||
# Backend
|
||||
backend-home:
|
||||
pattern: '/admin'
|
||||
path: backend::user::index
|
||||
|
|
|
|||
10
app/controllers/backend/UserController.php
Normal file
10
app/controllers/backend/UserController.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\Backend;
|
||||
|
||||
class UserController extends \Phalcon\Mvc\Controller
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -9,12 +9,19 @@ use Phalcon\Mvc\Application;
|
|||
|
||||
class Bootstrap extends Injectable
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $_app;
|
||||
|
||||
public function __construct(DiInterface $di = null)
|
||||
{
|
||||
if ($di === null) {
|
||||
$di = new DiDefault();
|
||||
}
|
||||
$this->setDI($di);
|
||||
|
||||
$this->_app = new Application();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -34,6 +41,14 @@ class Bootstrap extends Injectable
|
|||
$di->get('debugger')->listen(true, true);
|
||||
}
|
||||
|
||||
// Modules
|
||||
$this->_app->registerModules([
|
||||
'main' => [ 'className' => 'App\Module\Main' ],
|
||||
'backend' => [ 'className' => 'App\Module\Backend' ],
|
||||
]);
|
||||
|
||||
$this->_app->setDefaultModule('main');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +59,7 @@ class Bootstrap extends Injectable
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$app = new Application($this->getDI());
|
||||
return $app->handle()->getContent();
|
||||
$this->_app->setDI($this->getDI());
|
||||
return $this->_app->handle()->getContent();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ class Services extends DiDefault
|
|||
$loader->registerNamespaces(array(
|
||||
'App\Controller' => $config->application->controllersDir,
|
||||
'App\Listener' => $config->application->listenersDir,
|
||||
'App\Module' => $config->application->modulesDir,
|
||||
'App\Model' => $config->application->modelsDir,
|
||||
'App\Form' => $config->application->formsDir,
|
||||
'Httpcb' => $config->application->libraryDir,
|
||||
|
|
@ -222,7 +223,7 @@ class Services extends DiDefault
|
|||
|
||||
$view = new View();
|
||||
|
||||
$view->setViewsDir($config->application->viewsDir);
|
||||
$view->setViewsDir([ $config->application->viewsDir ]);
|
||||
$view->setLayoutsDir('_layouts/');
|
||||
$view->setPartialsDir('_partials/');
|
||||
|
||||
|
|
|
|||
12
app/modules/Backend.php
Normal file
12
app/modules/Backend.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
class Backend extends Base
|
||||
{
|
||||
protected $_controllerPath = APP_PATH . '/app/controllers/backend';
|
||||
|
||||
protected $_controllerNamespace = 'App\Controller\Backend';
|
||||
|
||||
protected $_viewDir = '../app/views/backend/';
|
||||
}
|
||||
47
app/modules/Base.php
Normal file
47
app/modules/Base.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
use Phalcon\Loader,
|
||||
Phalcon\DiInterface,
|
||||
Phalcon\Mvc\Dispatcher,
|
||||
Phalcon\Mvc\ModuleDefinitionInterface;
|
||||
|
||||
abstract class Base implements ModuleDefinitionInterface
|
||||
{
|
||||
protected $_controllerPath;
|
||||
|
||||
protected $_controllerNamespace;
|
||||
|
||||
protected $_viewDir;
|
||||
|
||||
/**
|
||||
* Register a specific autoloader for the module
|
||||
*/
|
||||
public function registerAutoloaders(DiInterface $di = null)
|
||||
{
|
||||
$loader = new Loader();
|
||||
|
||||
$loader->registerNamespaces([
|
||||
$this->_controllerNamespace => $this->_controllerPath,
|
||||
]);
|
||||
|
||||
$loader->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register specific services for the module
|
||||
*/
|
||||
public function registerServices(DiInterface $di)
|
||||
{
|
||||
$dispatcher = $di->get('dispatcher');
|
||||
|
||||
$dispatcher->setDefaultNamespace($this->_controllerNamespace);
|
||||
|
||||
$di->get('view')->setViewsDir(array_merge(
|
||||
[ $this->_viewDir ],
|
||||
(array) $di->get('view')->getViewsDir()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
12
app/modules/Main.php
Normal file
12
app/modules/Main.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Module;
|
||||
|
||||
class Main extends Base
|
||||
{
|
||||
protected $_controllerPath = APP_PATH . '/app/controllers';
|
||||
|
||||
protected $_controllerNamespace = 'App\Controller';
|
||||
|
||||
protected $_viewDir = '../app/views/main/';
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<header class="head-section">
|
||||
<div class="top-section">
|
||||
{% include "_templates/navigation.volt" %}
|
||||
{% include "_components/navigation.volt" %}
|
||||
</div>
|
||||
|
||||
{% block masthead %}{% endblock %}
|
||||
|
|
@ -20,14 +20,14 @@
|
|||
|
||||
<main class="content-section">
|
||||
|
||||
{% include "_templates/flash.volt" %}
|
||||
{% include "_components/flash.volt" %}
|
||||
|
||||
{{ content() }}
|
||||
|
||||
</main>
|
||||
|
||||
<div class="footer-section">
|
||||
{% include "_templates/footer.volt" %}
|
||||
{% include "_components/footer.volt" %}
|
||||
</div>
|
||||
|
||||
{{ assets.outputJs() }}
|
||||
2
app/views/backend/user/index.volt
Normal file
2
app/views/backend/user/index.volt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
<h1>Backend</h1>
|
||||
Reference in a new issue