Question

I used authentication in zend module but when i render it gives me error like

 Zend\View\Renderer\PhpRenderer::render: Unable to render template "calendar/index/login"; resolver could not resolve to a files

here is my module.config.php:

<?php
 return array(
'controllers' => array(
    'invokables' => array(
        'Calendar\Controller\Index' => 'Calendar\Controller\IndexController',
        'Calendar\Controller\User'      => 'Calendar\Controller\UserController',
        'Calendar\Controller\Calendar' => 'Calendar\Controller\CalendarController',
        'Calendar\Controller\Event' => 'Calendar\Controller\EventController'
    ),
),

'router' => array(
    'routes' => array(
        /*###############*/
        //index
        'admin_index' => array(
            'type'=>'segment',
            'options' => array(
                'route'=>'/calendar/admin[/]',
                'defaults'=>array('controller'=>'Calendar\Controller\Index','action'=>'index')
            )
        ),
        //login
        'admin_login' => array(
            'type'=>'literal',
            'options' => array(
                'route'=>'/calendar/admin/login',
                'defaults'=>array('controller'=>'Calendar\Controller\Index','action'=>'login')
            )
        ),
        //logout
        'admin_logout' => array(
            'type'=>'literal',
            'options' => array(
                'route'=>'/calendar/admin/logout',
                'defaults'=>array('controller'=>'Calendar\Controller\Index','action'=>'logout')
            )
        ),
        //user index
        'admin_user' => array(
            'type'=>'segment',
            'options' => array(
                'route'=>'/calendar/admin/user[/]',
                'defaults'=>array('controller'=>'Calendar\Controller\User','action'=>'index')
            )
        ),
        //user add
        'admin_user_add' => array(
            'type'=>'segment',
            'options' => array(
                'route'=>'/calendar/admin/user/add[/]',
                'defaults'=>array('controller'=>'Calendar\Controller\User','action'=>'add')
            )
        ),
        //user edit
        'admin_user_edit' => array(
            'type'=>'segment',
            'options' => array(
                'route' =>'/calendar/admin/user/edit[/:id]',
                'constraints' => array(
                'action' => 'edit',
                'id' => '[a-zA-Z0-9_-]+',
                ),
                'defaults'=>array('controller'=>'Calendar\Controller\User','action'=>'edit')
            )
        ),
        //user profile
        'admin_profile' => array(
                'type'=>'segment',
                'options' => array(
                        'route'=>'/calendar/admin/profile[/]',
                        'defaults'=>array('controller'=>'Calendar\Controller\Index','action'=>'profile')
                )
        ),
        'calendar' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/calendar[/:action][/:id]',
                'constraints' => array(
                    'action'   => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'       => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Calendar\Controller\Calendar',
                    'action'     => 'index',
                ),
            ),
        ),
        'event' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/event[/:action][/:id][/:unixTime][/:allDay]',
                'constraints' => array(
                    'action'   => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'       => '[0-9]+',
                    'unixTime' => '[0-9]+',
                    'allDay'   => '0|1',
                ),
                'defaults' => array(
                    'controller' => 'Calendar\Controller\Event',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),

'view_manager' => array(
    'template_path_stack' => array(
        'calendar' => __DIR__ . '/../view',
    ),
),
);

and here is my controller action:

 public function loginAction(){
    //$this->layout('layout/login-layout.phtml');

    $login_error=false;
    $loginForm = new LoginForm();

    if ($this->request->isPost())
    {
        $loginForm->setData($this->request->getPost());
        if ($loginForm->isValid())
        {
            //die("dgdgdgdgdgdgdgdg");
            $data = $loginForm->getData();
            $authService = $this->getServiceLocator()
            ->get('doctrine.authenticationservice.odm_default');

            $adapter = $authService->getAdapter();
            $adapter->setIdentityValue($data['username']);
            $adapter->setCredentialValue(md5($data['password']));
            $authResult = $authService->authenticate();
            //for disable authentication comment here////////////////////////////
            if ($authResult->isValid()) {
                $identity = $authResult->getIdentity();
                //$authService->getStorage()->write($identity);
                $this->redirect()->toRoute('admin_index');
            }
            else {
                $identity =false;
                $login_error= true;
            }
            //for disable authentication comment here////////////////////////////
        }
    }
    //
    return new ViewModel(array(
            'loginForm' => $loginForm,
            'login_error' => $login_error,
    ));
}
Était-ce utile?

La solution

That error occurs when you forgot to make the actual for your view. You need to create that template and place it in the appropriate view directory. Then this error should go away.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top