有没有人找到解决这个问题的办法?我也有同样的问题。
我的配置yml:
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_server%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
#Gedmo Package extension for Symfony and Doctrine
mappings:
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree
is_bundle: false
gedmo_sortable:
type: annotation
prefix: Gedmo\Sortable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Sortable/Entity"
alias: GedmoTree
is_bundle: false
[...]
stof_doctrine_extensions:
default_locale: "%locale%"
translation_fallback: true
orm:
default:
timestampable: true
blameable: true
我的doctrine_extension.yml包含在配置文件中:
services:
extension.listener:
class: Omega\HomeBundle\Library\Listener\DoctrineExtensionListener
calls:
- [ setContainer, [@service_container]]
tags:
# 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.sortable:
class: Gedmo\Sortable\SortableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
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 ] ]
gedmo.listener.blameable:
class: Gedmo\Blameable\BlameableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
- [ setUserValue, [ @security.token_storage ] ]
我为自己创建了一个trait来处理created、updated、updated_by和createdby字段:
namespace HomeBundle\Traits;
use Doctrine\ORM\Mapping as ORM;
use Omega\UserBundle\Entity\Users;
use Gedmo\Mapping\Annotation as Gedmo;
trait LogableTrait
{
/**
* @var Users
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\Users")
* @ORM\JoinColumn(name="log_created_by", referencedColumnName="id")
*/
protected $CreatedBy;
/**
* @var Users
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\Users")
* @ORM\JoinColumn(name="log_updated_by", referencedColumnName="id")
*/
protected $UpdatedBy;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created", type="datetime")
* @var \DateTime
*/
protected $created;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="updated", type="datetime")
* @var \DateTime
*/
protected $updated;
/**
* @return Users
*/
public function getCreatedBy ()
{
return $this->CreatedBy;
}
/**
* @param Users $CreatedBy
*
* @return $this
*/
public function setCreatedBy (Users $CreatedBy )
{
$this->CreatedBy = $CreatedBy;
return $this;
}
/**
* @return Users
*/
public function getUpdatedBy ()
{
return $this->UpdatedBy;
}
/**
* @param Users $UpdatedBy
*
* @return $this
*/
public function setUpdatedBy (Users $UpdatedBy )
{
$this->UpdatedBy = $UpdatedBy;
return $this;
}
}
但每次我使用此捆绑包时,我都会得到:
The class 'Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage' was not found in the chain configured namespaces Gedmo\Tree\Entity, Gedmo\Sortable\Entity, JMS\JobQueueBundle\Entity, AccountingBundle\Entity, DocumentsBundle\Entity, EavBundle\Entity, HomeBundle\Entity, UserBundle\Entity, CustomerBundle\Entity, Jns\Bundle\XhprofBundle\Entity
我希望有人能帮助我。
3条答案
按热度按时间laik7k3q1#
对于任何一个像我一样有同样问题的人来说,这个可指责的功能不起作用:
我的解决方案是用一种不同的方法实现BlamableListener:
为该受责备的人调整服务:
你需要把Map库复制到和监听器本身相同的位置。2调整命名空间就可以了。3看起来在symfony 2. 7中一些结构发生了变化,所以插件不再开箱即用。
nzkunb0c2#
如果要更新updated_by字段,则必须指定该字段,以便在更新该字段时,在updated_by中执行此操作。例如:
请注意field=“已更新”
a14dhokn3#
只需创建DoctrineExtensionSubscriber