Reputation: 5248
Guys am creating an Auth module and inside my AuthController
I have three methods:
1. loginAction()
2. autheticateAction()
3. logoutAction()
Problem is when I submit the form the autheticate()
method is not executed :
$form->setAttribute('action', $this->url('login/process',array('action' => 'authenticate', )));
The exception says 'I must have a view for that action':
Zend\View\Renderer\PhpRenderer::render: Unable to render template "auth/auth/authenticate"; resolver could not resolve to a file
I just need that method for process submiting data!!!
Inside loginAction()
I just return form and messages for render and autheticationAction
is for processing data:
public function loginAction()
{
//if already login, redirect to 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() as $message)
{
//save message temporary into flashmessenger
$this->flashmessenger()->addMessage($message);
}
if ($result->isValid()) {
$redirect = 'success';
//check if it 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 my 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 a way to not define specific view
for every action? I really don't need view for this 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}
Upvotes: 2
Views: 80