在过去一周左右的时间里,我一直在使用 Zend 和 Doctrine。我已经掌握了基本插入和选择的窍门,还可以使用 DQL 从连接的表中进行选择。我遇到的问题是保留关联实体。我得到的错误是这样的:(path)htdocs\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:96 with the message 'Class "" does not exist'.
我的代码如下...
这是主要实体(“多”侧的实体)
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\Factory as InputFactory;
/**
* ClientUser
*
* @ORM\Table()
* @ORM\Entity
*/
class ClientUser extends SystemUser
{
/**
* @var integer
*
* @ORM\OneToOne(targetEntity="SystemUser", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $id;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Client", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="client", referencedColumnName="id")
*/
private $client;
protected $_inputFilter;
//Other stuff here...
}
这是“客户”关联实体...
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* Client
*
* @ORM\Table()
* @ORM\Entity
*/
class Client implements InputFilterAwareInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="client_name", type="string", length=255)
*/
private $clientName;
/**
* @var integer
*
* @ORM\Column(name="loggable_hours", type="integer")
*/
private $loggableHours;
/**
* @var float
*
* @ORM\Column(name="normal_rate", type="decimal", scale=2)
*/
private $normalRate;
/**
* @var float
*
* @ORM\Column(name="critical_rate", type="decimal", scale=2)
*/
private $criticalRate;
/**
* @var string
*
* @ORM\Column(name="start_date", type="string")
*/
private $startDate;
/**
* @var boolean
*
* @ORM\Column(name="enabled", type="boolean")
*/
private $enabled;
/**
* @var integer
*
* @ORM\Column(name="critical_hours", type="integer")
*/
private $criticalHours;
/**
*
* @var type
*/
protected $_inputFilter;
//Other stuff (getters,setters, etc)
}
ClientUser 与以下内容具有一对一的关系:
namespace Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
/**
* SystemUser
*
* @ORM\Table()
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="user_type", type="integer")
* @ORM\DiscriminatorMap({1 = "DeveloperUser", 2 = "ClientUser"})
*
*/
class SystemUser implements InputFilterAwareInterface {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=100, unique=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="user_first_name", type="string", length=255)
*/
private $userFirstName;
/**
* @var string
*
* @ORM\Column(name="user_surname", type="string", length=255)
*/
private $userSurname;
/**
* @ORM\Column(type="string", length=32)
*/
private $salt;
/**
* @var \DateTime
*
* @ORM\Column(name="last_login", type="datetime")
*/
private $lastLogin = '0000-00-00 00:00:00';
/**
* @var bool
*
* @ORM\Column(name="enabled", type="boolean", options={"default" = 1})
*/
private $enabled = 1;
/**
* For the input filter...
*
* @var InputFilter
*/
protected $_inputFilter;
//The rest...
}
我完全不知道这里可能出了什么问题......为了完整起见,这里是控制器“添加”操作......
public function addAction() {
//To add clients
$form = new ClientUserForm($this->getServiceLocator()
->get('Doctrine\ORM\EntityManager'));
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$clientUser = new ClientUser();
$form->setInputFilter($clientUser->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$clientUser->populate($form->getData());
/**
*This bottom line is where I get the exception!
*/
$this->getEntityManager()->persist($clientUser);
$this->getEntityManager()->flush();
//Redirect
return $this->redirect()->toRoute('client_user');
}
}
return array ('form' => $form);
}
任何帮助都是极好的!如果我只知道应该是哪个班级“”,我可能会比现在更好!谢谢女士们先生们,你们摇滚!
编辑-
忘记添加这 2 个 PHP 警告...
警告: spl_object_hash() 期望参数 1 是对象,整数在 (path)\htdocs\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php 1588 行
警告:get_class() 期望参数 1 是对象,整数在 (path)\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php 第 1596 行给出