您可以按如下方式设置新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
是可写的。您不需要完全遵循上述方法 - 您始终可以用应用程序需要的任何内容替换配置变量。