2

我将 Zend Framework 与 Doctrine 2 和 mongoDB 结合使用。到现在为止还挺好。

现在我正在重写我的自定义验证类,以检查数据库中是否已经存在用户名。(此代码在 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,它运行良好,那么问题出在哪里?

提前致谢!

4

1 回答 1

3

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

于 2012-01-31T23:49:47.747 回答