我的 zf2 控制器中有以下代码:
<?php
namespace Accounting\Controller;
use Zend\Mvc\Controller\ActionController,
Zend\View\Model\ViewModel,
Accounting\Model,
Zend\Paginator,
Accounting\Scripts\CMSTranslator;
class AdminController extends ActionController {
protected $translator;
public function setTranslator(CMSTranslator $translator) {
$this->translator = $translator;
return $this;
}
public function __construct(\Doctrine\ORM\EntityManager $em,CMSTranslator $translator) {
$this->em = $em;
//$this->translator = new \Zend\Translator\Translator('ArrayAdapter', __DIR__ . '/../../../lang/lang-fa.php', 'fa');
$this->translator = $translator;
\Zend\Registry::set('tr', $this->translator);
// now you can use the EntityManager!
}
如您所见,我正在使用 zend\translator 模块。
我想将它添加到我的控制器构造函数中的视图中。我已经尝试过:
return ViewModel(array('tr'=>$translator));
但这不起作用。
请帮忙。