@nikolay-mihaylov,
Here is my view configuration:
/**
* Initializes the View services and Volt
*/
protected function initView()
{
$config = $this->diContainer->getShared('config');
$profiler = null;
if ($config->app->debug && $config->app->profiler) {
$profiler = $this->diContainer->getShared('profiler');
$benchmark = $profiler->start(__METHOD__, [], 'Bootstrap');
}
/** @var \Phalcon\Registry $registry */
$registry = $this->diContainer->getShared('registry');
$options = [
'compiledPath' => $config->app->cacheDir . '/volt/',
'compiledSeparator' => '_',
'compiledExtension' => '.php',
'compileAlways' => boolval('development' === $registry->mode),
'stat' => true,
];
$view = new PhViewSimple();
$view->setViewsDir(APP_PATH . '/app/views/');
$view->registerEngines(
[
'.volt' => function ($view) use ($config, $options) {
$volt = new PhVolt($view, $this->diContainer);
$volt->setOptions($options);
$compiler = $volt->getCompiler();
/**
* Register the PHP extension, to be able to use PHP functions in Volt
*/
$compiler->addExtension(new Php());
$compiler->addFunction('replace', 'preg_replace');
$compiler->addFunction('substring', 'mb_substr');
$compiler->addFunction('strtotime', 'strtotime');
$compiler->addFunction('implode', 'implode');
// $compiler->addFunction('first_letter', function ($text) {
// return mb_substr($text, 0, 1);
// });
$compiler->addFunction(
'latinize',
function($resolvedArgs, $exprArgs) use ($compiler)
{
$text = $compiler->expression($exprArgs[0]['expr']);
return 'transliterator_transliterate(
\'Any-Latin; Latin-ASCII;\', ' .
$text .
')';
// return iconv('UTF-8', 'ASCII//TRANSLIT', $text);
}
);
// return e.g. https://img.website.com/api/image/ad0733dc-1042-59ab-d5c1-dccfc23fe997/size/640x291
$compiler->addFunction(
'get_image_url',
function ($resolvedArgs, $exprArgs) use ($compiler, $config)
{
$filename = $compiler->expression($exprArgs[0]['expr']);
$resolution = $compiler->expression($exprArgs[1]['expr']);
return Image::getImageUrl($filename, $resolution, $config->app);
}
);
$compiler->addFunction(
'resolve_image_urls',
function ($resolvedArgs, $exprArgs) use ($compiler, $config)
{
$htmlBody = $compiler->expression($exprArgs[0]['expr']);
return Image::resolveImageUrlsInHtmlBody($htmlBody, $config->app);
}
);
return $volt;
},
]
);
$this->diContainer->setShared('viewSimple', $view);
if ($config->app->debug && $config->app->profiler) {
$profiler->stop($benchmark);
}
}
The most important thing is this line:
$options = [
// [...]
'compileAlways' => boolval('development' === $registry->mode),
// [...]
];
Let's say I have my search engine under following url:
https://website.test/en/search
https://website.test/pl/szukaj
https://website.test/pl/szukaj/strona/2?q=some-term
Phalcon PHP will create following cache files in production mode:
_en_search.cache
_pl_szukaj.cache
_pl_szukaj.cache_strona_2_.cache
I don't see any other way than disabling production mode.
Maybe someone will have better idea...