我正在寻找一种方法来测试连接是否与 Doctrine 2 一起工作。
由于在我的应用程序中用户可以自己更改信息连接,我想检查用户是否输入了正确的登录名和密码。
我怎样才能做到这一点?
我试图将此代码放入 try/catch 块中:
try{
$entityManager = $this->getEntityManager() ;
$repository = $entityManager->getRepository('Authentification\Entity\User');
$userToIdentify = $repository->findOneBy(array('login' => $this->_username, 'password' => $this->_password));
}catch(Exception $e){
$code = Result::FAILURE ;
$identity = "unknow" ;
$messages = array(
"message" => "Wrong login/password combination",
) ;
}
问题是即使信息连接正确,我也无法捕捉到异常。
否则我会收到以下错误:
<b>Fatal error</b>: Uncaught exception 'Zend\View\Exception\RuntimeException'
with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template
"layout/layout"; resolver could not resolve to a file' in C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php:451 Stack trace: #0 C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\View\View.php(203): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) #1 C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(128): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) #2 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))#3 C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(469): call_user_func(Array, Object(Zend\Mvc\MvcEvent))#4 C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\EventManager\EventMa in <b>C:\xampp\htdocs\poemsV3\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php</b> on line <b>451</b><br />
您对我如何测试连接是否有效有任何想法吗?
谢谢你。