I used an abstract class like this and then extend from there, it is a bit annoying that the layout path is always prefixed with module path :( you can use a ./../ but cannot seem to enter a absolute path for some reason :(
<?php
namespace CeptPhalcon\Module;
class AbstractModule implements \Phalcon\Mvc\ModuleDefinitionInterface {
/**
* We use composer, thanks for the fish
*/
public function registerAutoloaders() {
}
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
public function registerServices($di) {
$reflector = new \ReflectionClass(get_class($this));
$filename = $reflector->getFileName();
$viewDir = dirname($filename).'/../../views/';
if (is_dir($viewDir)) {
//Registering the view component
$view = $di->get('view');
if (!$view) {
$view = new \Phalcon\Mvc\View();
$view = $di->set('view', $view);
}
$view->setViewsDir($viewDir);
}
}
}
And in my bootstrap i already register the view..
$view = new \Phalcon\Mvc\View();
$view->setLayoutsDir('/../../../views/layout/');
$view->setTemplateAfter('main');
$this->di['view'] = $view;