Created
February 13, 2014 09:53
-
-
Save yuuan/8972485 to your computer and use it in GitHub Desktop.
Phalcon の project/app/config/services.php を編集して Volt に date フィルターを追加してみた。
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 | |
// ... | |
/** | |
* Setting up the view component | |
*/ | |
$di->set('view', function () use ($config) { | |
$view = new View(); | |
$view->setViewsDir($config->application->viewsDir); | |
$view->registerEngines(array( | |
'.volt' => function ($view, $di) use ($config) { | |
$volt = new VoltEngine($view, $di); | |
$volt->setOptions(array( | |
'compiledPath' => $config->application->cacheDir, | |
'compiledSeparator' => '_' | |
)); | |
$compiler = $volt->getCompiler(); | |
$compiler->addFilter('date', function($resolvedArgs, $exprArgs) { | |
$args = explode(',', $resolvedArgs . ", 'Y/m/d H:i:s'"); | |
return "date($args[1], strtotime($args[0]))"; | |
}); | |
return $volt; | |
}, | |
'.phtml' => 'Phalcon\Mvc\View\Engine\Php' | |
)); | |
return $view; | |
}, true); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment