Reputation: 906
I am using zf2 and doctrine2 for creating a user controller my registration action is working fine but in log in action, i a getting an exeception like:
F:\PHP\EasySurvey\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96
Message:
Class '' does not exist
Stack trace:
#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 {
In my controller:
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,
));
}
In my module.php:
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
},
)
);
}
In 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;
}
},
),
),
My User entity:
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;
}
}
Upvotes: 2
Views: 1880
Reputation: 183
A bit late but: I had exactly the same issue. In my case it occured because I made a mistake in the module.config.php. I placed the authentication config block inside the doctrine.driver config instead of directly inside the doctrine config.
So in my case mabe.berlin was right, the error occured because the identityClass property wasn't set.
Upvotes: 2
Reputation: 1073
From a quick view it looks like the property DoctrineModule\Options\Authentication::$identityClass
is not set.
That's the reason why you get a empty class not exist error.
Upvotes: 2