내 zf2 컨트롤러에 다음 코드를 가지고 :설정 컨트롤러 constructer에서 일부 변수보기
<?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!
}
당신은 내가 젠드 \ 번역기 모듈을 사용하고 볼 수 있듯이.
내 컨트롤러 생성자의보기에 추가하고 싶습니다. 이미 시도 :
return ViewModel(array('tr'=>$translator));
하지만 작동하지 않습니다.
도와주세요.
이 정말 \ 젠드 \ 레지스트리를 사용하는 어떤 이유가 안 최종 솔루션 - 기본적으로 글로벌 변수는 당신이 '잘못되고있는 레지스트리에 넣어 객체 좋은 양식. 레지스트리를 사용하는 대신 DI를 사용하여 Translator를 구성하고 필요할 때마다 주입하십시오. – superdweebie
예 ... 답글을 게시했습니다 –