I'm using Zend Framework in combination with Doctrine 2 and mongoDB. So far so good.
Now I'm rewriting my custom validation class in order to check if a username already exists in the database. (This code worked fine with ORM and MySQL, but not now with ODM and mongoDB).
So my custom validation class looks like this:
<?php
class Project_Validate_UsernameUnique extends Zend_Validate_Abstract {
const USERNAME_EXISTS = '';
protected $_messageTemplates = array (
self::USERNAME_EXISTS => "'%value%' is taken. Please choose another username."
);
public function isValid($value) {
// setting value for the form
$this->_setValue($value);
// get the document manager and repository
$front = Zend_Controller_Front::getInstance();
$dm = $front->getParam('bootstrap')->getResource('odm');
$userRepository = $dm->getRepository('Entities\User');
$user = $userRepository->findOneBy(array('username' => $value));
// if an user was found, return false
if ($user) {
$this->_error(self::USERNAME_EXISTS);
return false;
}
return true;
}
}
But I get this error here:
Warning: file_put_contents(/Applications/XAMPP/xamppfiles/htdocs/project/application/models/Hydrators/EntitiesUserHydrator.php) [function.file-put-contents]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/project/library/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php on line 343
I also tried findBy and without the array annotation (findByUsername or findOneByUsername), but still, either I get this error or somehow "nothing". With ORM and MySQL it worked perfect, so where is the problem?
Thanks in advance!