我对DoctrineExtensions Bundle有一个奇怪的问题。
我完成安装并且没有错误。
但是我的更新"和"创造"活动无效。
实体:
Use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* Price
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="pspiess\LetsplayBundle\Entity\PriceRepository")
*/
class Price {
public function __construct() {
//$this->created = new \DateTime();
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @var \Doctrine\Common\Collections\ArrayCollection $fields
*
* @ORM\ManyToMany(targetEntity="pspiess\LetsplayBundle\Entity\Field", mappedBy="prices")
* */
protected $fields;
protected $field;
/**
* @var decimal
*
* @ORM\Column(name="price", type="decimal", precision=9, scale=2)
*/
private $price;
/**
* @var integer
*
* @ORM\Column(name="weekdayfrom", type="smallint", nullable=true)
*/
private $weekdayfrom;
/**
* @var integer
*
* @ORM\Column(name="weekdayto", type="smallint", nullable=true)
*/
private $weekdayto;
/**
* @var string
*
* @ORM\Column(name="indentifier", type="string", length=255)
*/
private $indentifier;
/**
* @var \DateTime
*
* @ORM\Column(name="timefrom", type="time")
*/
private $timefrom;
/**
* @var \DateTime
*
* @ORM\Column(name="timeto", type="time")
*/
private $timeto;
/**
* @var string
*
* @ORM\Column(name="note", type="text", nullable=true)
*/
private $note;
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @var \DateTime
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="changed", type="datetime")
*/
private $changed;
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set price
*
* @param integer $price
* @return Price
*/
public function setPrice($price) {
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return integer
*/
public function getPrice() {
return $this->price;
}
/**
* Set weekdayfrom
*
* @param integer $weekdayfrom
* @return Price
*/
public function setWeekdayfrom($weekdayfrom) {
$this->weekdayfrom = $weekdayfrom;
return $this;
}
/**
* Get weekdayfrom
*
* @return integer
*/
public function getWeekdayfrom() {
return $this->weekdayfrom;
}
/**
* Set weekdayto
*
* @param integer $weekdayto
* @return Price
*/
public function setWeekdayto($weekdayto) {
$this->weekdayto = $weekdayto;
return $this;
}
/**
* Get weekday
*
* @return integer
*/
public function getWeekdayto() {
return $this->weekdayto;
}
/**
* Set indentifier
*
* @param string $indentifier
* @return Price
*/
public function setIndentifier($indentifier) {
$this->indentifier = $indentifier;
return $this;
}
/**
* Get indentifier
*
* @return string
*/
public function getIndentifier() {
return $this->indentifier;
}
/**
* Set timefrom
*
* @param \DateTime $timefrom
* @return Price
*/
public function setTimefrom($timefrom) {
$this->timefrom = $timefrom;
return $this;
}
/**
* Get timefrom
*
* @return \DateTime
*/
public function getTimefrom() {
return $this->timefrom;
}
/**
* Set timeto
*
* @param \DateTime $timeto
* @return Price
*/
public function setTimeto($timeto) {
$this->timeto = $timeto;
return $this;
}
/**
* Get timeto
*
* @return \DateTime
*/
public function getTimeto() {
return $this->timeto;
}
/**
* Set note
*
* @param string $note
* @return Price
*/
public function setNote($note) {
$this->note = $note;
return $this;
}
/**
* Get note
*
* @return string
*/
public function getNote() {
return $this->note;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated() {
return $this->created;
}
/**
* Set changed
*
* @param \DateTime $changed
* @return Price
*/
public function setChanged($changed) {
$this->changed = $changed;
return $this;
}
/**
* Get changed
*
* @return \DateTime
*/
public function getChanged() {
return $this->changed;
}
/**
* Add field
*
* @param \pspiess\LetsplayBundle\Entity\Field $field
* @return Price
*/
public function addField(\pspiess\LetsplayBundle\Entity\Field $field) {
$this->fields[] = $field;
return $this;
}
/**
* Remove field
*
* @param \pspiess\LetsplayBundle\Entity\Field $field
*/
public function removeField(\pspiess\LetsplayBundle\Entity\Field $field) {
$this->fields->removeElement($field);
}
/**
* Get field
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getField() {
return $this->fields;
}
/*
* @return string
*/
public function __toString() {
return $this->getIndentifier();
}
}
我的Config.yml
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
translatable:
type: annotation
alias: Gedmo
prefix: Gedmo\Translatable\Entity
# make sure vendor library location is correct
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
loggable:
type: annotation
alias: Gedmo
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
tree:
type: annotation
alias: Gedmo
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
我的doctrine_extensions.yml
services:
# KernelRequest listener
extension.listener:
class: pspiess\AppBundle\Listener\DoctrineExtensionListener
calls:
- [ setContainer, [ @service_container ] ]
tags:
# translatable sets locale after router processing
- { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
# loggable hooks user username if one is in security context
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
# Doctrine Extension listeners to handle behaviors
gedmo.listener.tree:
class: Gedmo\Tree\TreeListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.translatable:
class: Gedmo\Translatable\TranslatableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
- [ setDefaultLocale, [ %locale% ] ]
- [ setTranslationFallback, [ false ] ]
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.sortable:
class: Gedmo\Sortable\SortableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.loggable:
class: Gedmo\Loggable\LoggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
我不知道我在这里做错了什么......
答案 0 :(得分:1)
您的配置似乎正确无误。所以你确定已经导入了你的doctrine_extensions.yml
你应该有类似的东西:
在app / config / config.yml中:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: doctrine_extensions.yml }
答案 1 :(得分:1)
几个小时后,我找到了解决问题的方法。我发现命令架构:更新不能正常工作,所以我尝试修复它。
当我删除Bundle / Resources / config / doctrine目录中的* .orm.xml文件时,一切正常。我认为当您使用xml和注释配置时,Symfony有问题...
不太确定文件是如何到达那里的,因为我只有注释配置。 我认为这是由于学说:mapping:import命令。此命令将现有数据库的模式存储到.orm.xml文件中。