简体   繁体   English

如何清除zf2中的路由错误?

[英]How to remove routing error in zf2?

I used authentication in zend module but when i render it gives me error like 我在zend模块中使用了身份验证,但是当我渲染它时会出现类似

 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: 这是我的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,
    ));
}

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. 然后,该错误应消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM