我在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,
));
}
答案 0 :(得分:0)
当您忘记为视图制作实际内容时,会发生该错误。您需要创建该模板并将其放在相应的视图目录中。然后这个错误就会消失。