如何让 DoctrineExtensions 与 doctrine 2.3 / symfony 3.4 一起工作?
How to get DoctrineExtensions sluggable working with doctrine 2.3 / symfony 3.4?
我尝试在我的项目中使用 sluggable doctrine extension。我按照在 Internet 上找到的设置步骤进行操作,但它似乎不起作用(@Gedmo\Slug 似乎不是 called/triggered)。
目的是获得 post 标题。
我在 PHP 7.1 上使用 Symfony 3.4 和 Doctrine 2.3。
有人知道如何获得这项工作吗,我将不胜感激。
我在 AppKernel 中添加了包 (new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle()
)
这是我的其他项目文件:
composer.json
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0",
"stof/doctrine-extensions-bundle": "^1.3.0",
"gedmo/doctrine-extensions": "^2.3.4"
},
app/config/config.yml
# Stof\DoctrineExtensionsBundle configuration
stof_doctrine_extensions:
orm:
default:
sluggable: true
src/xxx/xxxBundle/Entity/Advert.php
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
* @ORM\HasLifecycleCallbacks()
*/
class Advert
{
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(name="slug", type="string", length=255, unique=true, nullable=true)
*/
private $slug;
我刚弄明白!
我忘记在我的包中添加该服务。
所以在我的 services.yml 中,我添加了以下行:
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: pgsql }
calls:
- [ setAnnotationReader, [ "@annotation_reader" ] ]
我尝试在我的项目中使用 sluggable doctrine extension。我按照在 Internet 上找到的设置步骤进行操作,但它似乎不起作用(@Gedmo\Slug 似乎不是 called/triggered)。
目的是获得 post 标题。
我在 PHP 7.1 上使用 Symfony 3.4 和 Doctrine 2.3。
有人知道如何获得这项工作吗,我将不胜感激。
我在 AppKernel 中添加了包 (new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle()
)
这是我的其他项目文件:
composer.json
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0",
"stof/doctrine-extensions-bundle": "^1.3.0",
"gedmo/doctrine-extensions": "^2.3.4"
},
app/config/config.yml
# Stof\DoctrineExtensionsBundle configuration
stof_doctrine_extensions:
orm:
default:
sluggable: true
src/xxx/xxxBundle/Entity/Advert.php
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
* @ORM\HasLifecycleCallbacks()
*/
class Advert
{
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(name="slug", type="string", length=255, unique=true, nullable=true)
*/
private $slug;
我刚弄明白!
我忘记在我的包中添加该服务。
所以在我的 services.yml 中,我添加了以下行:
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: pgsql }
calls:
- [ setAnnotationReader, [ "@annotation_reader" ] ]