我正在尝试在我的 zend 2 项目中实现理论水合器。我正在使用学说的官方文档
我收到两个警告和一个错误。以下是页面顶部的警告。
警告:缺少 DoctrineModule\Stdlib\Hydrator\DoctrineObject::__construct() 的参数 2,在第 16 行的 /path/to/my/project/module/Notes/src/Notes/Form/AssignForm.php 中调用并在 / 中定义path/to/my/project/vendor/doctrine/doctrine-module/src/DoctrineModule/Stdlib/Hydrator/DoctrineObject.php 在第 71 行
注意:未定义变量:第 76 行 /path/to/my/project/vendor/doctrine/doctrine-module/src/DoctrineModule/Stdlib/Hydrator/DoctrineObject.php 中的 targetClass
这是错误:
An error occurred 执行过程中发生错误;请稍后再试。附加信息:Doctrine\Common\Persistence\Mapping\MappingException
文件:
/path/to/my/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:96
信息:
Class '' does not exist
这是我的实体:
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class Assigned{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/** @ORM\Column(type="string")
* @access protected
*/
protected $loan_number;
/** @ORM\Column(type="string")
* @access protected
*/
protected $claim_status;
/** @ORM\Column(type="datetime")
* @access protected
*/
protected $hold_date;
/** @ORM\Column(type="datetime")
* @access protected
*/
protected $vsi_date;
/** @ORM\Column(type="integer")
* @access protected
*/
protected $hold_status;
/** @ORM\Column(type="integer")
* @access protected
*/
protected $vsi_status;
/**
* @param string $id
* @return Assign
*/
// id should be auto incremental in database.
/*
public function setId($id)
{
$this->id = $id;
return $this;
}
*/
/**
* @return string $id;
*/
public function getId()
{
return $this->id;
}
/**
* @param string $loan_number
* @access public
* @return Assigned
*/
public function setLoanNumber($loan_number)
{
$this->loan_number = $loan_number;
return $this;
}
/**
* @return string $loan_number
*/
public function getLoanNumber()
{
return $this->loan_number;
}
/**
* @param string $claim_status
* @access public
* @return Assigned
*/
public function setClaimStatus($claim_status)
{
$this->claim_status = $claim_status;
return $this;
}
/**
* @return string $claim_status;
*/
public function getClaimStatus()
{
return $this->claim_status;
}
/**
* @param datetime $hold_date
* @access public
* @return Assigned
*/
public function setHoldDate($hold_date)
{
$this->hold_date = new \DateTime($hold_date);
return $this;
}
/**
* @return datetime $hold_date;
*/
public function getHoldDate()
{
return $this->hold_date;
}
/**
* @param datetime $vsi_date
* @access public
* @return Assigned
*/
public function setVsiDate($vsi_date)
{
$this->vsi_date = new \DateTime($vsi_date);
return $this;
}
/**
* @return datetime $vsi_date;
*/
public function getVsiDate()
{
return $this->vsi_date;
}
/**
* @param integer $hold_status
* @access public
* @return Assigned
*/
public function setHoldStatus($hold_status)
{
$this->hold_status = $hold_status;
return $this;
}
/**
* @return integer $hold_status;
*/
public function getHoldStatus($hold_status)
{
return $this->hold_status;
}
/**
* @param integer $vsi_status
* @access public
* @return Assigned
*/
public function setVsiStatus($vsi_status)
{
$this->vsi_status = $vsi_status;
return $this;
}
/**
* @return integer $vsi_status;
*/
public function getVsiStatus()
{
return $this->vsi_status;
}
}
这是我的控制器
<?php
namespace Notes\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Doctrine\ORM\EntityManager;
use Application\Entity\Assigned;
use Notes\Form\AssignForm;
use Notes\Form\NotesFieldset;
class NotesController extends AbstractActionController
{
protected $objectManager;
public function indexAction()
{
return new ViewModel();
}
public function addAction()
{
// Get your ObjectManager from the ServiceManager
$objectManager = $this->getOBjectManager();
$form = new AssignForm($objectManager);
// Create a new, empty entity and bind it to the form
$assigned = new Assigned();
$form->bind($assigned);
if ($this->request->isPost()) {
$form->setData($this->request->getPost());
if ($form->isValid()) {
$objectManager->persist($assigned);
$objectManager->flush();
}
}
return array('form' => $form);
}
public function getOBjectManager(){
if(!$this->objectManager){
$this->objectManager = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
}
return $this->objectManager;
}
}
这是我的表单类:
<?php
namespace Notes\Form;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Form;
use Notes\Form\NotesFieldset;
class AssignForm extends Form
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('assigned');
// The form will hydrate an object of type "BlogPost"
$this->setHydrator(new DoctrineHydrator($objectManager));
// Add the user fieldset, and set it as the base fieldset
$notesFieldset = new NotesFieldset($objectManager);
$notesFieldset->setUseAsBaseFieldset(true);
$this->add($notesFieldset);
// … add CSRF and submit elements …
// Optionally set your validation group here
}
}
这是 Fieldset 类
<?php
namespace Notes\Form;
use Application\Entity\Assigned;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class NotesFieldset extends Fieldset implements InputFilterProviderInterface
{
protected $inputFilter;
public function __construct(ObjectManager $objectManager)
{
parent::__construct('assigned');
$this->setHydrator(new DoctrineHydrator($objectManager))
->setObject(new Assigned());
$this->add(array(
'type' => 'Zend\Form\Element\Hidden',
'name' => 'id'
));
$this->add(array(
'type' => 'Zend\Form\Element\Text',
'name' => 'loan_number',
'options' => array(
'label' => 'Loan Number'
)
));
$this->add(array(
'type' => 'Zend\Form\Element\Text',
'name' => 'claim_status',
'options' => array(
'label' => 'Claim Status'
)
));
$this->add(array(
'type' => 'Zend\Form\Element\Text',
'name' => 'hold_date',
'options' => array(
'label' => 'Hold Date'
)
));
$this->add(array(
'type' => 'Zend\Form\Element\Text',
'name' => 'vsi_date',
'options' => array(
'label' => 'VSI Date'
)
));
$this->add(array(
'type' => 'Zend\Form\Element\Text',
'name' => 'hold_status',
'options' => array(
'label' => 'Hold Status'
)
));
$this->add(array(
'name' => 'vsi_status',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'VSI Status',
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
/**
* Define InputFilterSpecifications
*
* @access public
* @return array
*/
public function getInputFilterSpecification()
{
return array(
'id' => array(
'required' => false
),
'name' => array(
'required' => true
),
'loan_number' => array(
'required' => true
),
'claim_status' => array(
'required' => true
),
'hold_date' => array(
'required' => true
),
'hold_status' => array(
'required' => true
),
'vsi_date' => array(
'required' => true
),
'hold_status' => array(
'required' => true
),
);
}
}
它是说:类''不存在。但是消息中没有给出类名。
除此之外,我将这些库用于我的作曲家的教义。
"doctrine/doctrine-orm-module": "0.7.*",
"doctrine/migrations": "dev-master",
"doctrine/common": "2.4.*@dev",
"doctrine/annotations": "1.0.*@dev",
"doctrine/data-fixtures": "1.0.*@dev",
"doctrine/cache": "1.0.*@dev",
"zf-commons/zfc-user-doctrine-orm": "dev-master",
请告诉我我的实现中缺少什么。我在 github 中有一个关于不完整示例文档的教义的未解决问题。这是问题的链接。如果是这种情况,那么请建议我正确实施。