[尝试一个新的答案,因为这种方法与以前的答案有本质的不同。]
我假设您会Zend_Date::toString()
在视图中调用。
因此,也许您可以将格式覆盖列表存储在配置文件中。在 期间Bootstrap
,检查加载的语言环境是否需要覆盖,然后将格式存储在视图中。然后,每当您输出日期时,请使用该格式。
像这样的东西:
在application/configs/application.ini
:
dateFormat.nl_NL = "d-m-Y"
在application/Bootstrap.php
:
protected function _initDateFormat()
{
// Bootstrap and grab the view
$this->bootstrap('view');
$view = $this->getResource('view');
// grab the date format overrides from options or null for locale-default
$options = $this->getOptions();
$this->bootstrap('locale');
$locale = $this->getResource('locale');
$dateFormat = isset($options['dateFormat'][$locale])
? $options['dateFormat'][$locale]
: null;
// stash the dateFormat into the view
$view->dateFormat = $dateFormat;
}
最后在视图脚本中,$date
对象在哪里Zend_Date
:
<p>The date is <?= $date->toString($this->dateFormat) ?>.</p>
如果$view->dateFormat
为 null,则将使用当前语言环境的格式。否则,您的覆盖将适用。