我正在集成 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;
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;
}
}
班上
<?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;
}
我收到错误:可捕获的致命错误:传递给 Doctrine\ODM\MongoDB\Hydrator\HydratorFactory::hydrate() 的参数 3 必须是数组类型,给定 null,在 /home/gabiru/www/twitradar_mongo/ 中调用library/Doctrine/ODM/MongoDB/UnitOfWork.php 在第 2518 行
我已经搜索并没有找到任何有相同问题的人的任何结果,有人对此有任何想法吗?
第三个参数是变量$hint,我不知道参数设置在哪里。