Zend 2.2 trouble for HTTP Authentication -
i try make http authentication 1 of module using zend framework 2.2, code inspired official documentation, in there :
$request=$this->getrequest(); $response=$this->getresponse(); assert($request instanceof zend\http\request); assert($response instanceof zend\http\response);
the problem assertion goes false, seems $request , $response come class, script's not working. how request , response zend\http\request|response in controller ?
many thanks.
if want set http auth entire module, here's (at least how did it) :
in module.php :
public function onbootstrap(mvcevent $e){ $sharedevents=$e->getapplication()->geteventmanager()->getsharedmanager(); $sharedevents->attach(__namespace__,mvcevent::event_dispatch, array($this, 'authhttp')); } public function authhttp(mvcevent $e){ $servicemanager = $e->getapplication()->getservicemanager(); $request=$e->getrequest(); $response=$e->getresponse(); if(!( $request instanceof \zend\http\request && $response instanceof \zend\http\response )){ return; // we're not in http context - cli application? } // adapter config/password etc... $authadapter=$servicemanager->get('admin\authenticationadapter'); $authadapter->setrequest($request); $authadapter->setresponse($response); $result=$authadapter->authenticate(); if($result->isvalid()){ return true; // ok } $response->setcontent('access denied'); $response->setstatuscode(\zend\http\response::status_code_401); $e->setresult($response); // short-circuit application end return false; }
that's :). work page of module !
Comments
Post a Comment