Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (67 sloc) 2.01 KB
<?php
namespace Modules\Backend;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\DiInterface;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Db\Adapter\Pdo\Mysql as MySQLAdapter;
class Module implements ModuleDefinitionInterface
{
/**
* Registers the module auto-loader
*
* @param DiInterface $di
*/
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
$loader->registerNamespaces(
[
'Modules\Backend\Controllers' => __DIR__ . '/controllers/',
'Modules\Backend\Models' => __DIR__ . '/models/',
]
);
$loader->register();
}
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$config = include __DIR__ . "/config/config.php";
$di['dispatcher'] = function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Modules\Backend\Controllers');
return $dispatcher;
};
/**
* Setting up the view component
*/
$di['view'] = function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('../../common/layouts/');
$view->setTemplateAfter('main');
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use ($config) {
return new MySQLAdapter(
[
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
]
);
};
}
}
You can’t perform that action at this time.