DoctrineExtensions SoftDeleteable的配置条目:gedmo / doctrine
我试图使用softdelete
/ doctrine扩展的softdelete
选项,但由于某种原因,当我调用romove()
,数据库中的记录被删除而不是更新deletedAt
字段。
在这里,doc告诉我们更新配置:
$ config-> addFilter('soft-deleteable','Gedmo SoftDeleteable Filter SoftDeleteableFilter');
这只是我尝试的一个例子:
# app/config/config.yml
doctrine:
orm:
entity_managers:
default:
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true
参考文献(仅其中几个):
因此,简单来说,我该如何在config.yml中配置它?
CONTROLLER
public function delete($id)
{
$profile = $this->profileRepository->findOneBy(['id' => $id]);
if (!$profile instanceof Profile) {
throw new ........
}
$this->entityManager->remove($profile);
$this->entityManager->flush();
return true;
}
实体
use GedmoMappingAnnotation as Gedmo;
/**
* @ORMEntity()
* @ORMTable(name="profile")
* @GedmoSoftDeleteable(fieldName="deletedAt")
*/
class Profile
{
/**
* @ORMColumn(name="deletedAt", type="datetime", nullable=true)
*/
private $deletedAt;
......
}
COMPOSER.JSON
"require": {
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"gedmo/doctrine-extensions": "2.3.*@dev",
......
},
CONFIG.YML
doctrine:
dbal:
default_connection: front
connections:
front:
driver: %database_driver%
host: %database_host%
........
back:
driver: %database_driver%
host: %database_host%
........
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: front
entity_managers:
front:
connection: front
mappings:
MyWebsiteBundle:
dir: Entity
FOSUserBundle: ~
back:
connection: back
映射信息:
inanzzz@inanzzz:/var/www/html/local$ php app/console doctrine:mapping:info
Found 8 mapped entities:
[OK] MyBundleEntityAbstractMerchantProfile
[OK] MyBundleEntityAbstractIntegration
[OK] MyBundleEntityAPIConsumer
[OK] MyBundleWebsiteBundleEntityUser
[OK] MyBundleWebsiteBundleEntityProfile
[OK] MyBundleWebsiteBundleEntityIntegration
[OK] FOSUserBundleModelGroup
[OK] FOSUserBundleModelUser
解:
在composer.json中包含stof/doctrine-extensions-bundle
"stof/doctrine-extensions-bundle": "1.2.*@dev",
包在这里。 文档在这里。
在AppKernel中启用包: new StofDoctrineExtensionsBundleStofDoctrineExtensionsBundle()
因为我在config.yml中有多个实体管理器,所以我做了:
stof_doctrine_extensions:
orm:
em1:
softdeleteable: true
doctrine:
dbal:
default_connection: em1
connections:
em1:
driver: %database_driver%
host: %database_host%
.......
em2:
driver: %database_driver%
host: %database_host%
.......
em3:
driver: %mws_database_driver%
host: %mws_database_host%
.......
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: em1
entity_managers:
em1:
connection: em1
mappings:
MyWebsiteBundle:
dir: Entity
FOSUserBundle: ~
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true
em2:
connection: em2
em3:
connection: em3
这是我配置它的方式
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true
链接地址: http://www.djcxy.com/p/65031.html
上一篇: Config entries for DoctrineExtensions SoftDeleteable: gedmo/doctrine
下一篇: How to apply a Doctrine filter to a whole bundle in Symfony?