まず、下手な英語で申し訳ありません。おやすみ/昼/午後 (お住まいの地域によって異なります) ここで検索できることをお尋ねしたら申し訳ありません。コントローラーで認証を確認する必要があるため、マスター コントローラーを実装し、すべての実際のコントローラーをそれに拡張します。マスター コントローラーで認証を確認し、うまく行っていますが、認証されていないユーザーをリダイレクトしようとするとクラッシュします。Webで検索すると、「init、preDispatchなど」のメソッドは存在せず、「construct」メソッドだけであることに気付いたので、試してみましたが、constructにはイベントマネージャーがないため、ここで停止します。 ..これは私のコードです:
public function __construct(){
$r = new SimpleRouteStack();
$r->addRoute('logoff', Literal::factory(array(
'route'=>'/suporte/logoff',
'defaults' => array(
'action' => 'logoff',
'controller' => 'Suporte\Controller\Index',
)
)
)
);
$e = new MvcEvent();
$e->setRouter($r);
$this->setEvent($e);
$this->getEvent()->setResponse(new Response());
$this->getEventManager()->attach('*',array($this,'mvcPreDispatch'),100);
public function mvcPreDispatch(){
$uri = explode('/',substr($_SERVER['REQUEST_URI'],1));
$uri[2] = !isset($uri[2]) ? "index" : $uri[2];
$auth = new AuthenticationService();
$identity = $auth->getStorage()->read();
$acl = $identity[2];
if (!$auth->hasIdentity()){
$this->redirect()->toRoute('suporte/logoff');
}elseif ( !$acl->hasResource($uri[0].'/'.$uri[1])
||
!$acl->isAllowed($identity[1],
$uri[0].'/'.$uri[1],
$uri[2]
)
)
$this->redirect()->toRoute('logoff');
else{
/* $this->layout()->id = $identity[0]->getId();
$this->layout()->nome = $identity[0]->getNome();
$this->layout()->cargo = $identity[0]->getCargo(); */
echo "permitido";
//$this->layout()->recursos = $this->acl->getResources();
}
}