如何使用教义2.3 / symfony 3.4获得可扩展的DoctrineExtensions?

时间:2018-08-24 08:32:23

标签: php symfony doctrine-orm symfony-3.4 doctrine-extensions

我试图在我的项目中进行缓慢的理论扩展。我遵循在Internet上找到的设置步骤,但似乎不起作用(@Gedmo \ Slug似乎没有被调用/触发)。

目的是要塞一个帖子标题。

我在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; 

1 个答案:

答案 0 :(得分:0)

我才知道!

我忘记将服务添加到我的捆绑软件中。

因此,在我的services.yml中,添加以下行:

gedmo.listener.sluggable:
    class: Gedmo\Sluggable\SluggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: pgsql }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]