小编Kar*_*kar的帖子

多个实体持有doctrine2 Zend

我有3个实体Users,UserProfileStaffs

用户配置文件通过用户ID链接到Users表使用userprofileid将Staff表链接到userprofile

管理员创建用户配置文件并生成注册号,用户名和密码.

我想在users表中添加用户记录,然后添加用户配置文件,然后将配置文件ID添加到staff表中.

我想按顺序坚持三个实体

我试图为用户创建一个实例

$this->userent->setUsername('xxx');
$this->em->persist($this->userent);
$this->em->flush();
Run Code Online (Sandbox Code Playgroud)

然后:

$this->profileent->setFirstname('xxx');
$this->em->persist($this->profileent);
$this->em->flush();
Run Code Online (Sandbox Code Playgroud)

基本上,一个表单在三个实体之间共享,我想按顺序插入三个表,

更新

除了users实体我有一个usertype链接到用户的实体...我想只保留外键.我有

setUserType(Usertype $userType) 方法用户中user_type实体的实例

当我做

 $this->userent = new Users();
$this->userent->setUserType($this->em->getRepository('\Campus\Entity\Usertype')->findByUserType("admin")) 
Run Code Online (Sandbox Code Playgroud)

我收到了错误

Argument 1 passed to Campus\Entity\Users::setUserType() must be an instance of Campus\Entity\Usertype, array given
Run Code Online (Sandbox Code Playgroud)

如果我传递数组的值,这是一个Usertype的实例

我得到一个错误,说需要ArrayCollection..help数组请!!!

Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in D:\xampp\htdocs\zend\library\Doctrine\ORM\UnitOfWork.php on line 406 defined in D:\xampp\htdocs\zend\library\Doctrine\Common\Collections\ArrayCollection.php on line 46
Run Code Online (Sandbox Code Playgroud)

php doctrine-orm

2
推荐指数
1
解决办法
3407
查看次数

标签 统计

doctrine-orm ×1

php ×1