Last active
December 20, 2015 19:39
-
-
Save romanodesouza/6185176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<!-- Setting a block that will NOT be overrided --> | |
{% block someBlock %}{% endblock %} | |
</head> | |
<body> | |
<!-- Using a component from Di --> | |
{{ myService.doAction() }} | |
<!-- Setting a block that will be overrided --> | |
{% block content %}{% endblock %} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Phalcon\Config; | |
use Phalcon\Mvc\View; | |
use Phalcon\Mvc\View\Engine\Volt; | |
$config = new Config( | |
array( | |
'app' => array( | |
'cacheDir' => __DIR__ . '/Views/cache/', | |
'compileAlways' => true | |
) | |
) | |
); | |
$di->setShared('view', function() use ($config) { | |
$view = new View(); | |
$view->setViewsDir(__DIR__ . '/Views/'); | |
$view->registerEngines(array( | |
'.volt' => function($view, $di) use ($config) { | |
$volt = new Volt($view, $di); | |
$volt->setOptions(array( | |
'compiledPath' => $config->app->cacheDir, | |
'compileAlways' => $config->app->compileAlways, | |
'compiledSeparator' => '_' | |
)); | |
return $volt; | |
} | |
)); | |
return $view; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.volt' %} | |
<!-- I'm overriding only the 'content' block --> | |
{% block content %}Phalcon rox \m/{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// setShared causes WSOD when "compileAlways" is true | |
$di->setShared('myService', function() { | |
return new MyService; | |
}); | |
// "set" works properly when "compileAlways" is true | |
// EDIT: The example below doesn't work in recent Phalcon versions too | |
$di->set('myService', function() { | |
return new MyService; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment