簡體   English   中英

如何清除zf2中的路由錯誤?

[英]How to remove routing error in zf2?

我在zend模塊中使用了身份驗證,但是當我渲染它時會出現類似

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

這是我的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',
    ),
),
);

這是我的控制器動作:

 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,
    ));
}

當您忘記為視圖添加實際值時,將發生該錯誤。 您需要創建該模板並將其放置在適當的視圖目錄中。 然后,該錯誤應消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM