您可以设置新的compiledPath和其他选项如下:
假设您的配置中有这些变量:
[views]
path = '/home/user/www/app/views/'
[volt]
path = '/home/user/www/app/volt/'
extension = '.compiled'
separator = '%%'
stat = 1
然后你可以按照手册来做:
// Assuming that this is in a class and `_di` is your DI container
$config = $this->_di->get('config');
$di = $this->_di;
/**
* Setup the volt service
*/
$this->_di->set(
'volt',
function($view, $di) use($config)
{
$volt = new Volt($view, $di);
$volt->setOptions(
array(
'compiledPath' => $config->app->volt->path,
'compiledExtension' => $config->app->volt->extension,
'compiledSeparator' => $config->app->volt->separator,
'stat' => (bool) $config->app->volt->stat,
)
);
return $volt;
}
);
/**
* Setup the view service
*/
$this->_di->set(
'view',
function() use ($config, $di)
{
$view = new \Phalcon\Mvc\View();
$view->setViewsDir(ROOT_PATH . $config->app->path->views);
$view->registerEngines(array('.volt' => 'volt'));
return $view;
}
);
或者你可以按照下面的实现(上面那个是首选)
$di->set('view', function() use ($config, $di) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir($config->views->path);
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(
array(
'compiledPath' => $config->volt->path,
'compiledExtension' => $config->volt->extension,
'compiledSeparator' => $config->volt->separator,
'stat' => (bool) $config->volt->stat,
)
);
/**
* Register Volt
*/
$view->registerEngines(array('.volt' => $volt));
return $view;
});
确保您的$config->volt->path 是可写的。您无需完全遵循上述方法 - 您始终可以将配置变量替换为您的应用程序需要的任何内容。