Php MongoDB+;条令+;泽德
我正在整合Zend和Doctrine 2与MongoDB合作。 我正在使用快速入门框架 这里是Doctrine.phpPhp MongoDB+;条令+;泽德,php,mongodb,doctrine-orm,zend-framework2,Php,Mongodb,Doctrine Orm,Zend Framework2,我正在整合Zend和Doctrine 2与MongoDB合作。 我正在使用快速入门框架 这里是Doctrine.php <?php use Doctrine\MongoDB\Connection; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Annotations; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; us
<?php
use Doctrine\MongoDB\Connection;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Annotations;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
{
protected $_options = array();
private $manager;
public function __set($config, $null) {
$this->_options = array(
'connection' => array(
'dbname' => $config['connection']['dbname'],
),
'modelDir' => $config['modelDir'],
'proxyDir' => $config['proxyDir'],
'proxyNamespace' => $config['proxyNamespace'],
'hydratorDir' => $config['proxyDir'],
'hydratorNamespace' => $config['proxyNamespace'],
'autoGenerateProxyClasses' => $config['autoGenerateProxyClasses']
);
}
public function init()
{
$zendConfig = $this->getOptions();
if(!empty($zendConfig)) Zend_Registry::set('config', $zendConfig);
$options = Zend_Registry::get('config');
$this->__set($options,null);
$config = new \Doctrine\ODM\MongoDB\Configuration;
$config->setDefaultDB($options['connection']['dbname']);
$config->setProxyDir($this->_options['proxyDir']);
$config->setProxyNamespace($this->_options['proxyNamespace']);
$config->setHydratorDir($this->_options['hydratorDir']);
$config->setHydratorNamespace($this->_options['hydratorNamespace']);
$config->setMetadataDriverImpl(AnnotationDriver::create($this->_options['modelDir']));
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::registerAnnotationClasses();
$dm = DocumentManager::create(new Connection(), $config);
return $dm;
}
}
我得到了错误:可捕获致命错误:传递给Doctrine\ODM\MongoDB\Hydrator\HydratorFactory::hydrate()的参数3必须是数组类型,给定null,在第2518行的/home/gabiru/www/twitradar\u mongo/library/Doctrine/ODM/MongoDB/UnitOfWork.php中调用
我已经搜索过了,没有找到任何有相同问题的人的结果,有人知道吗
第三个参数是变量$hint,我不知道参数设置在哪里。我解决了这个问题。这是代理目录上的权限问题。如果有人想要获得Zend+Doctrine2+MongoDB快速启动,这里是我的=>Gabriel,我遇到了与您描述的完全相同的问题,并且怀疑这是某种文件/目录权限问题,因为此代码在我的其他机器上以及在我们的开发/生产机器上都能工作。我试图将mongodb用户添加到db目录中,但没有多大区别。如果您能详细介绍一下您的解决方案,特别是您授予了哪些代理目录权限以及哪些类型的代理目录,这将非常有帮助。提前谢谢你,你好,亚历克斯。我只给了/application/proxy 777权限。对我来说很好。我不太明白你到底做了什么,如果没有帮助,我很抱歉,但我使用mongodb用户只是为了验证连接。连接是这样的:$options=array('username'=>'The_username','password'=>'The_password')$dm=DocumentManager::create(新连接('localhost',$options),$config);我不在目录中使用mongodb用户,只在连接中使用。当我试图用ID保存一个引用字段的记录时,我也遇到了同样的问题。它使用整个对象工作。
<?php
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** @ODM\Document */
class Application_Model_Guestbook
{
/**
* @ODM\Id
*/
public $id;
/** @ODM\String */
public $email;
/** @ODM\String */
public $comment;
/** @ODM\Date */
public $created;
public function setGuestbook($comment)
{
$this->email = $comment['email'];
$this->comment = $comment['comment'];
$this->created = date('d-m-Y H:i:s');
}
public function getGuestbook()
{
return $this;
}
}
public function signAction()
{
$request = $this->getRequest();
$this->getHelper('loadResource')->form('sign', 'Guestbook');
$form = new Application_Form_Guestbook();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
$guestbook = new Application_Model_Guestbook;
$guestbook->setGuestbook($form->getValues());
try
{
$this->em->persist($guestbook);
$this->em->flush($guestbook);
return $this->_helper->redirector('index');
}
catch (Exception $e)
{
throw new Exception($e);
}
}
}
$this->view->form = $form;
}