php - Action is not executed -
guys creating auth module , inside authcontroller
have 3 methods:
1. loginaction()
2. autheticateaction()
3. logoutaction()
problem when submit form autheticate()
method not executed :
$form->setattribute('action', $this->url('login/process',array('action' => 'authenticate', )));
the exception says 'i must have view action':
zend\view\renderer\phprenderer::render: unable render template "auth/auth/authenticate"; resolver not resolve file
i need method process submiting data!!!
inside loginaction()
return form , messages render , autheticationaction
processing data:
public function loginaction() { //if login, redirect success page if ($this->getauthservice()->hasidentity()){ return $this->redirect()->toroute('success'); } $form = $this->getform(); return array( 'form' => $form, 'messages' => $this->flashmessenger()->getmessages() ); } public function authenticateaction() { $form = $this->getform(); $redirect = 'login'; $request = $this->getrequest(); if ($request->ispost()){ $form->setdata($request->getpost()); if ($form->isvalid()){ //check authentication... $this->getauthservice()->getadapter() ->setidentity($request->getpost('username')) ->setcredential($request->getpost('password')); $result = $this->getauthservice()->authenticate(); foreach($result->getmessages() $message) { //save message temporary flashmessenger $this->flashmessenger()->addmessage($message); } if ($result->isvalid()) { $redirect = 'success'; //check if has rememberme : if ($request->getpost('rememberme') == 1 ) { $this->getsessionstorage() ->setrememberme(1); //set storage again $this->getauthservice()->setstorage($this->getsessionstorage()); } $this->getauthservice()->getstorage()->write($request->getpost('username')); } } } return $this->redirect()->toroute($redirect); }
and here route config:
'login' => array( 'type' => 'literal', 'options' => array( 'route' => '/auth', 'defaults' => array( '__namespace__' => 'application\controller', 'controller' => 'auth', 'action' => 'login', ), ), 'may_terminate' => true, 'child_routes' => array( 'process' => array( 'type' => 'segment', 'options' => array( 'route' => '/[:action]', 'constraints' => array( 'controller' => '[a-za-z][a-za-z0-9_-]*', 'action' => '[a-za-z][a-za-z0-9_-]*', ), 'defaults' => array( ), ), ), ), ),
is there way not define specific view
every action? don't need view autheticationaction()
stack trace:
#0 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-view\src\view.php(205): zend\view\renderer\phprenderer->render(object(zend\view\model\viewmodel)) #1 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-view\src\view.php(233): zend\view\view->render(object(zend\view\model\viewmodel)) #2 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-view\src\view.php(198): zend\view\view->renderchildren(object(zend\view\model\viewmodel)) #3 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-mvc\src\view\http\defaultrenderingstrategy.php(103): zend\view\view->render(object(zend\view\model\viewmodel)) #4 [internal function]: zend\mvc\view\http\defaultrenderingstrategy->render(object(zend\mvc\mvcevent)) #5 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-eventmanager\src\eventmanager.php(444): call_user_func(array, object(zend\mvc\mvcevent)) #6 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-eventmanager\src\eventmanager.php(205): zend\eventmanager\eventmanager->triggerlisteners('render', object(zend\mvc\mvcevent), array) #7 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-mvc\src\application.php(353): zend\eventmanager\eventmanager->trigger('render', object(zend\mvc\mvcevent)) #8 d:\xampp\htdocs\addskproject\vendor\zendframework\zend-mvc\src\application.php(328): zend\mvc\application->completerequest(object(zend\mvc\mvcevent)) #9 d:\xampp\htdocs\addskproject\public\index.php(21): zend\mvc\application->run() #10 {main}
Comments
Post a Comment