DoctrineExtensions SoftDeleteable的配置条目:gedmo/doctrine-extensions [英] Config entries for DoctrineExtensions SoftDeleteable: gedmo/doctrine-extensions
问题描述
我正在尝试使用此处中,doc告诉我们使用以下命令更新配置:
$ config-> addFilter('soft-deleteable','Gedmo \ SoftDeleteable \ Filter \ SoftDeleteableFilter');
这只是我尝试的示例之一:
#app/config/config.yml教义:orm:实体经理:默认:筛选器:可软删除:类别:Gedmo \ SoftDeleteable \ Filter \ SoftDeleteableFilter已启用:true
参考文献(仅其中一些):
- DoctrineExtensions SoftDeleteable
- http://knplabs.com/en/blog/gedmo-doctrine-extensions-on-symfony2
- 无法在Symfony2中启用SoftDeleteable-无法识别的选项"filters";
所以问题很简单,如何在config.yml中配置它?
CONTROLLER
公共函数delete($ id){$ profile = $ this-> profileRepository-> findOneBy(['id'=> $ id]);if(!$ profile instanceof Profile){扔新.....}$ this-> entityManager-&remove($ profile);$ this-> entityManager-&flush();返回true;}
ENTITY
将Gedmo \ Mapping \ Annotation用作Gedmo;/*** @ORM \ Entity()* @ORM \ Table(name ="profile")* @Gedmo \ SoftDeleteable(fieldName ="deletedAt")*/班级简介{/*** @ORM \ Column(name ="deletedAt",type ="datetime",nullable = true)*/私人$ deletedAt;......}
COMPOSER.JSON
"require":{"symfony/symfony":"2.6.*",教义/规范":〜2.2,> = 2.2.3","doctrine/doctrine-bundle":〜1.2","gedmo/doctrine-extensions":"2.3.*@dev",......},
CONFIG.YML
原则:dbal:default_connection:前面连接:正面:驱动程序:%database_driver%主机:%database_host%........背部:驱动程序:%database_driver%主机:%database_host%........orm:auto_generate_proxy_classes:%kernel.debug%default_entity_manager:前面实体经理:正面:连接方式:前映射:MyWebsiteBundle:dir:实体FOSUserBundle:〜背部:连接方式:返回
映射信息:
inanzzz @ inanzzz:/var/www/html/local $ php app/console原则:mapping:info找到8个映射的实体:[确定] My \ Bundle \ Entity \ AbstractMerchantProfile[确定] My \ Bundle \ Entity \ AbstractIntegration[确定] My \ Bundle \ Entity \ APIConsumer[确定]我的\捆绑\网站捆绑\实体\用户[确定]我的\捆绑\网站捆绑\实体\个人资料[确定] My \ Bundle \ WebsiteBundle \ Entity \ Integration[确定] FOS \ UserBundle \ Model \ Group[确定] FOS \ UserBundle \ Model \ User
解决方案:
在composer.json中包含的 stof/doctrine-extensions-bundle
"stof/doctrine-extensions-bundle":"1.2.* @ dev",
在AppKernel中启用捆绑软件:新的Stof \ DoctrineExtensionsBundle \ StofDoctrineExtensionsBundle()
由于我在config.yml中有多个实体管理器,所以我做到了:
stof_doctrine_extensions:orm:em1:软删除:true教义:dbal:default_connection:em1连接:em1:驱动程序:%database_driver%主机:%database_host%.......em2:驱动程序:%database_driver%主机:%database_host%.......em3:驱动程序:%mws_database_driver%主机:%mws_database_host%.......orm:auto_generate_proxy_classes:%kernel.debug%default_entity_manager:em1实体经理:em1:连接:em1映射:MyWebsiteBundle:dir:实体FOSUserBundle:〜筛选器:可软删除:类别:Gedmo \ SoftDeleteable \ Filter \ SoftDeleteableFilter已启用:trueem2:连接:em2em3:连接:em3
I'm trying to use softdelete
option of gedmo/doctrine-extensions but for some reason when I call romove()
, the record in database gets removed instead of updating deletedAt
field.
In here, doc tells us to update config with:
$config->addFilter('soft-deleteable', 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
This is just one of the examples I tried:
# app/config/config.yml
doctrine:
orm:
entity_managers:
default:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
References (just a few of them):
- DoctrineExtensions SoftDeleteable
- http://knplabs.com/en/blog/gedmo-doctrine-extensions-on-symfony2
- Can't enable SoftDeleteable in Symfony2 - Unrecognized options "filters"
So the question in simple terms, how do I configure it in 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;
}
ENTITY
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity()
* @ORM\Table(name="profile")
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class Profile
{
/**
* @ORM\Column(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
MAPPING INFO:
inanzzz@inanzzz:/var/www/html/local$ php app/console doctrine:mapping:info
Found 8 mapped entities:
[OK] My\Bundle\Entity\AbstractMerchantProfile
[OK] My\Bundle\Entity\AbstractIntegration
[OK] My\Bundle\Entity\APIConsumer
[OK] My\Bundle\WebsiteBundle\Entity\User
[OK] My\Bundle\WebsiteBundle\Entity\Profile
[OK] My\Bundle\WebsiteBundle\Entity\Integration
[OK] FOS\UserBundle\Model\Group
[OK] FOS\UserBundle\Model\User
Solution:
Included stof/doctrine-extensions-bundle
in composer.json
"stof/doctrine-extensions-bundle": "1.2.*@dev",
Package is here. Documentation is here.
Enable bundle in AppKernel:
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle()
Since I have more than one entity managers in config.yml I did:
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: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
em2:
connection: em2
em3:
connection: em3
这篇关于DoctrineExtensions SoftDeleteable的配置条目:gedmo/doctrine-extensions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!