我使用zf2和doctrine2创建用户控制器我的注册操作正常但在登录操作中,我得到了一个例外:
F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96
消息:
Class '' does not exist
堆栈追踪:
#0 F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(43): Doctrine\Common\Persistence\Mapping\MappingException::nonExistingClass('')
#1 F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(267): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getParentClasses('')
#2 F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(297): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getParentClasses('')
#3 F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(211): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('')
#4 F:\PHP\EasySurvey\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(295): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('')
#5 F:\PHP\EasySurvey\vendor\doctrine\orm\lib\Doctrine\ORM\Repository\DefaultRepositoryFactory.php(67): Doctrine\ORM\EntityManager->getClassMetadata('')
#6 F:\PHP\EasySurvey\vendor\doctrine\orm\lib\Doctrine\ORM\Repository\DefaultRepositoryFactory.php(50): Doctrine\ORM\Repository\DefaultRepositoryFactory->createRepository(Object(Doctrine\ORM\EntityManager), '')
#7 F:\PHP\EasySurvey\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(759): Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository(Object(Doctrine\ORM\EntityManager), NULL)
#8 F:\PHP\EasySurvey\vendor\doctrine\doctrine-module\src\DoctrineModule\Options\Authentication.php(168): Doctrine\ORM\EntityManager->getRepository(NULL)
#9 F:\PHP\EasySurvey\vendor\doctrine\doctrine-module\src\DoctrineModule\Authentication\Adapter\ObjectRepository.php(134): DoctrineModule\Options\Authentication->getObjectRepository()
#10 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\Authentication\AuthenticationService.php(110): DoctrineModule\Authentication\Adapter\ObjectRepository->authenticate()
#11 F:\PHP\EasySurvey\module\Easysurvey\src\Easysurvey\Controller\UserController.php(105): Zend\Authentication\AuthenticationService->authenticate()
#12 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): Easysurvey\Controller\UserController->loginAction()
#13 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#18 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#19 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#20 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#21 F:\PHP\EasySurvey\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#22 F:\PHP\EasySurvey\public\index.php(17): Zend\Mvc\Application->run()
#23 {
在我的控制器中:
public function loginAction()
{
if ($user = $this->identity()) {
// return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}
$form = new LoginForm();
$form->get('submit')->setValue('Log in');
$messages = null;
$request = $this->getRequest();
if ($request->isPost()) {
$form->setInputFilter(new LoginFilter($this->getServiceLocator()));
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$authService = $this->getServiceLocator()->get('Zend_Authentication_AuthenticationService');
$adapter = $authService->getAdapter();
$usernameOrEmail = $data['usernameOrEmail'];
// check for email first
if ($user = $this->getEntityManager()->getRepository('Easysurvey\Entity\User')->findOneBy(array('email' => $usernameOrEmail))) {
// Set username to the input array in place of the email
$data['usernameOrEmail'] = $user->getUsername();
}
$adapter->setIdentityValue($data['usernameOrEmail']);
$adapter->setCredentialValue($data['password']);
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
$identity = $authResult->getIdentity();
$authService->getStorage()->write($identity);
$time = 1209600; // 14 days (1209600/3600 = 336 hours => 336/24 = 14 days)
if ($data['rememberme']) {
$sessionManager = new \Zend\Session\SessionManager();
$sessionManager->rememberMe($time);
}
return $this->redirect()->toRoute('user');
}
foreach ($authResult->getMessages() as $message) {
$messages .= "$message\n";
}
}
}
/* $viewModel = new ViewModel();
$viewModel->setVariables(array('key' => 'value'))
->setTerminal(true);
return $viewModel; */
return new ViewModel(array(
'error' => 'Your authentication credentials are not valid',
'form' => $form,
'messages' => $messages,
));
}
在我的module.php中:
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
},
)
);
}
在module.config.php中:
'authentication' => array( // this part is for the Auth adapter from DoctrineModule/Authentication
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
// object_repository can be used instead of the object_manager key
'identity_class' => 'Easysurvey\Entity\User', //'Application\Entity\User',
'identity_property' => 'username', // 'username', // 'email',
'credential_property' => 'password', // 'password',
'credential_callable' => function(Entity\User $user, $passwordGiven) {
if ($user->getPassword() == Pbkdf2::calc('sha256', $passwordGiven, $user->getSalt(), 10000, 32)) {
return true;
} else {
return false;
}
},
),
),
我的用户实体:
namespace Easysurvey\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"UserName"}), @ORM\UniqueConstraint(name="email", columns={"Email"})})
* @ORM\Entity
*/
class User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="UserToken", type="string", length=100, nullable=false)
*/
private $usertoken;
/**
* @var string
*
* @ORM\Column(name="UserName", type="string", length=50, nullable=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="Email", type="string", length=255, nullable=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="DisplayName", type="string", length=50, nullable=true)
*/
private $displayname;
/**
* @var string
*
* @ORM\Column(name="Password", type="string", length=255, nullable=false)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="Salt", type="string", length=255, nullable=false)
*/
private $salt;
/**
* @var boolean
*
* @ORM\Column(name="ConfirmMail", type="boolean", nullable=false)
*/
private $confirmmail = '0';
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set usertoken
*
* @param string $usertoken
* @return User
*/
public function setUsertoken($usertoken)
{
$this->usertoken = $usertoken;
return $this;
}
/**
* Get usertoken
*
* @return string
*/
public function getUsertoken()
{
return $this->usertoken;
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set displayname
*
* @param string $displayname
* @return User
*/
public function setDisplayname($displayname)
{
$this->displayname = $displayname;
return $this;
}
/**
* Get displayname
*
* @return string
*/
public function getDisplayname()
{
return $this->displayname;
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set salt
*
* @param string $salt
* @return User
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set confirmmail
*
* @param boolean $confirmmail
* @return User
*/
public function setConfirmmail($confirmmail)
{
$this->confirmmail = $confirmmail;
return $this;
}
/**
* Get confirmmail
*
* @return boolean
*/
public function getConfirmmail()
{
return $this->confirmmail;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return User
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return User
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
}
答案 0 :(得分:2)
从快速查看,看起来未设置属性DoctrineModule\Options\Authentication::$identityClass
。
这就是为什么你得到一个空类不存在错误的原因。
答案 1 :(得分:2)
有点晚了但是: 我有完全相同的问题。在我的情况下它发生,因为我在module.config.php中犯了一个错误。我将身份验证配置块放在doctrine.driver配置中,而不是直接放在doctrine配置中。
所以在我的情况下,mabe.berlin是对的,错误发生是因为未设置identityClass属性。
答案 2 :(得分:-2)
没有人能够回答这个问题,所以更好的想法是使用zend身份验证而不是教义..
答案 3 :(得分:-2)
#square {
width: 100px;
height: 100px;
position: relative;
background: red;
transform: translate3d(0, 0, 0);
transition: transform .4s linear;
}
#square.animate {
transform: translate3d(-60px, 0, 0);
}