好吧,我沿着乔尔·韦哈根(Joel Verhagen)的路线使用了codeigniter中的doctrine2,而且情况一直很好,但是现在我有一个神秘的问题。
销毁物品时,事情正常工作:
$delete = $this->doctrine->em->getRepository('EntitiesItem')->findOneBy(array('slug' => $item));
$this->doctrine->em->remove($delete);
$this->doctrine->em->flush();
但是,在getRepository()之后,更新项目会默默地失败:
$item = $this->doctrine->em->getRepository('EntitiesItem')->findOneBy(array('id' => $id));
$item->setDescription(html_entity_decode($_POST['content']));
$this->doctrine->em->persist($item);
$this->doctrine->em->flush();
同一控制器,这就是每个操作中的所有代码。我所有的其他控制器都很好,但是在任何日志中都没有失败。将GetRepositor分开并在GetRepositor之后立即找到呼叫。将getrepository移动到__ -construct conduses update()中以发现。
想法?线索?似乎其他任何人最终要么朝着不同的方向发展,要么从未解决问题。
谢谢!
编辑:添加型号
yaml
项目
EntitiesItem:
type: entity
table: items
id:
id:
type: integer
primary: true
notnull: true
generator:
strategy: AUTO
fields:
title:
type: string(255)
notnull: true
slug:
type: string(255)
notnull: true
description:
type: string(255)
manyToOne:
type:
targetEntity: Type
inversedBy: item
joinColumn:
name: type_id
referencedColumnName: id
options:
charset: utf8
type: InnoDB
类型
EntitiesType:
type: entity
table: types
id:
id:
type: integer
primary: true
notnull: true
generator:
strategy: AUTO
fields:
title:
type: string(255)
notnull: true
slug:
type: string(255)
notnull: true
description:
type: string(255)
oneToMany:
items:
targetEntity: Item
orphanRemoval: true
mappedBy: type
manyToMany:
fields:
targetEntity: Field
inversedBy: types
joinTable:
name: fields_types
joinColumns:
type_id:
referencedColumnName: id
inverseJoinColumns:
field_id:
referencedColumnName: id
options:
charset: utf8
type: InnoDB
php
项目
<?php
namespace Entities;
use DoctrineORMMapping as ORM;
/**
* EntitiesItem
*/
class Item
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $title
*/
private $title;
/**
* @var string $description
*/
private $description;
/**
* @var DoctrineCommonCollectionsArrayCollection
*/
private $fields;
/**
* Constructor
*/
public function __construct()
{
$this->fields = new DoctrineCommonCollectionsArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Item
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return Item
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Add fields
*
* @param EntitiesField $fields
* @return Item
*/
public function addField(EntitiesField $fields)
{
$this->fields[] = $fields;
return $this;
}
/**
* Remove fields
*
* @param EntitiesField $fields
*/
public function removeField(EntitiesField $fields)
{
$this->fields->removeElement($fields);
}
/**
* Get fields
*
* @return DoctrineCommonCollectionsCollection
*/
public function getFields()
{
return $this->fields;
}
/**
* @var EntitiesType
*/
private $types;
/**
* Set types
*
* @param EntitiesType $types
* @return Item
*/
public function setTypes(EntitiesType $types = null)
{
$this->types = $types;
return $this;
}
/**
* Get types
*
* @return EntitiesType
*/
public function getTypes()
{
return $this->types;
}
/**
* @var EntitiesType
*/
private $type;
/**
* Set type
*
* @param EntitiesType $type
* @return Item
*/
public function setType(EntitiesType $type = null)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return EntitiesType
*/
public function getType()
{
return $this->type;
}
/**
* @var string $slug
*/
private $slug;
/**
* Set slug
*
* @param string $slug
* @return Item
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
}
类型
<?php
namespace Entities;
use DoctrineORMMapping as ORM;
/**
* EntitiesType
*/
class Type
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $title
*/
private $title;
/**
* @var string $description
*/
private $description;
/**
* @var DoctrineCommonCollectionsArrayCollection
*/
private $items;
/**
* Constructor
*/
public function __construct()
{
$this->items = new DoctrineCommonCollectionsArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Type
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return Type
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Add items
*
* @param EntitiesItem $items
* @return Type
*/
public function addItem(EntitiesItem $items)
{
$this->items[] = $items;
return $this;
}
/**
* Remove items
*
* @param EntitiesItem $items
*/
public function removeItem(EntitiesItem $items)
{
$this->items->removeElement($items);
}
/**
* Get items
*
* @return DoctrineCommonCollectionsCollection
*/
public function getItems()
{
return $this->items;
}
/**
* @var DoctrineCommonCollectionsArrayCollection
*/
private $fields;
/**
* Add fields
*
* @param EntitiesField $fields
* @return Type
*/
public function addField(EntitiesField $fields)
{
$this->fields[] = $fields;
return $this;
}
/**
* Remove fields
*
* @param EntitiesField $fields
*/
public function removeField(EntitiesField $fields)
{
$this->fields->removeElement($fields);
}
/**
* Get fields
*
* @return DoctrineCommonCollectionsCollection
*/
public function getFields()
{
return $this->fields;
}
/**
* @var string $slug
*/
private $slug;
/**
* Set slug
*
* @param string $slug
* @return Type
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
}
我修复了它。不幸的是,我不知道为什么。如果有人可以向我解释为什么这可以解决(或者一开始就是什么),我会接受您的答案。
加载项目存储库时,它将默默失败。加载类型存储库,并在其上进行Findall首先修复。这可能是因为项目是类型的孩子,但是必须事先做一个Findall()才能加载特定物品似乎很奇怪。
例如,在__construct()中这样做:
$this->typeR = $this->doctrine->em->getRepository('EntitiesType');
$data['types'] = $this->typeR->findAll();
$this->itemR = $this->doctrine->em->getRepository('EntitiesItem');
允许我在该控制器的必要时加载项目。
再次,这只是在服务器上。本地一切都很好。