我刚刚启动Zend Framework 2,并且希望将一种语言附加到doctype。
引导程序:
$this->layout()->setVariable('language', 'nl');
Layout.phtml
<html lang="<?php echo $language;?>">
这仅在Controller中有效,如何为引导程序解决此问题?
遮篷:
public function onBootstrap(MvcEvent $e) {
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->language = 'en';
}
// Now in your layout:
<html lang="<?php echo $this->language ?>">
您至少有两个选择:
您可以编写自定义视图帮助程序来解析和返回该语言,并在您的布局中使用它,例如:
<html lang="<?php echo $this->langHelper() ?>">
在Module.php的onBootstrap()
方法中,您可以将任何变量传递给布局,如下所示:
public function onBootstrap(MvcEvent $e) {
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->language = 'en';
}
// Now in your layout:
<html lang="<?php echo $this->language ?>">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句