2012-01-31 57 views
2

我使用Zend Framework与Doctrine 2和mongoDB结合使用。 目前为止这么好。ZendFramework,Doctrine 2 ODM与mongoDB - Hydrator错误

现在我正在重写自定义验证类,以检查数据库中是否已存在用户名。 (这段代码在ORM和MySQL上运行良好,但现在没有ODM和mongoDB)。

所以我自定义的验证类看起来是这样的:

<?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; 
    } 
} 

但我在这里得到这个错误:

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 

我也试过findBy并没有阵列注释(findByUsername或findOneByUsername),但仍然,或者我得到这个错误或者某种程度上“没有”。 使用ORM和MySQL它工作完美,所以问题在哪里?

在此先感谢!

回答

3

您的Hydrators文件夹是否可由PHP写入?

+0

嘿男人!这正是重点!我的主文件夹是可写的,但是我忘了将它添加到封闭的项目中!非常感谢!你让我今天一整天都感觉很好! =) – pvlsgnnks 2012-02-01 11:32:23

+0

Thax很多家伙=)。虽然我不知道我们为什么使用它! – 2013-02-11 10:56:18