标签: doctrine-extensions

Gedmo Doctrine Extensions - Sluggable + Translatable Yaml配置

我正在尝试使用gedmo doctrine扩展来翻译实体.

https://github.com/Atlantic18/DoctrineExtensions

我使用yml作为orm映射文件(自动生成实体).

orm.yml:

CS\ContentBundle\Entity\Post:
  type:  entity
  table: posts
  repositoryClass: CS\ContentBundle\Entity\PostRepository
  gedmo:
    soft_deleteable:
      field_name: deleted_at
    translation:
      locale: locale
  fields:
    id:
      type: integer
      length: 11
      id: true
      generator:
        strategy: AUTO
    title:
      type: string
      length: 500
      gedmo:
        - translatable
    slug:
      type: string
      length: 500
      gedmo:
        translatable: {}
        slug:
          separator: -
          fields:
            - title
Run Code Online (Sandbox Code Playgroud)

我可以毫无问题地翻译标题.但是slu is不行......

通常,在默认语言(tr)上,slug auto生成而没有任何生成过程.

实体文件:

<?php

namespace CS\ContentBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
use APY\DataGridBundle\Grid\Mapping as GRID;

/**
 * Post
 * @Gedmo\SoftDeleteable(fieldName="deleted_at", timeAware=false) …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm doctrine-extensions

15
推荐指数
1
解决办法
1万
查看次数

快速实体主义水化器

我正在寻求提高学说水合的速度.我以前一直在使用,HYDRATE_OBJECT但可以看到,在许多情况下,使用它可能会非常繁重.

我知道可用的最快的选项是HYDRATE_ARRAY,然后我提供了使用实体对象的许多好处.在实体方法中存在业务逻辑的情况下,这将被重复,但是由数组处理.

所以我所追求的是更便宜的物体保湿剂.我很高兴以速度的名义做出一些让步并放松一些功能.例如,如果它最终只是被读取,那就没问题了.同样,如果延迟加载不是一件事,那也没关系.

这种事情是存在还是我要求太多?

php object doctrine-orm doctrine-extensions

13
推荐指数
2
解决办法
4585
查看次数

Doctrine Extensions当更改位置超过1时,可排序无法正常工作

我使用Symfony 3.1 + Doctrine GEDMO扩展(通过StofDoctrineExtensionsBundle).我已将我的实体设置为具有可排序行为:

<?php

namespace AppBundle\Entity\Manual;

use AppBundle\Entity\Identifier;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Table(name="manual_pages")
 * @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
 */
class Manual
{
    use Identifier;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank(message="Toto pole musí být vypln?no")
     */
    private $title;

    /**
     * @ORM\Column(type="text")
     * @Assert\NotBlank(message="Toto pole musí být vypln?no")
     */
    private $content;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Manual\ManualImage", mappedBy="manual")
     * @ORM\OrderBy({"position"="ASC"})
     */
    private $images;

    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(type="integer", nullable=false)
     */
    private $position;

    /**
     * @return mixed
     */ …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-extensions stofdoctrineextensions

10
推荐指数
1
解决办法
1968
查看次数

Gedmo\Loggable记录未更改的数据

我正在使用Symfony2.2和StofDoctrineExtensionsBundle(以及Gedmo DoctrineExtensions).我有一个简单的实体

/**
 * @ORM\Entity
 * @Gedmo\Loggable
 * @ORM\Table(name="person")
 */
class Person {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

[...]

    /**
     * @ORM\Column(type="datetime", nullable=true)
     * @Assert\NotBlank()
     * @Assert\Date()
     * @Gedmo\Versioned
     */
    protected $birthdate;
}
Run Code Online (Sandbox Code Playgroud)

更改现有对象的属性时,将在表中完成日志条目ext_log_entries.此日志表中的条目仅包含已更改的列.我可以通过以下方式阅读日志:

$em = $this->getManager();
$repo = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
$person_repo = $em->getRepository('Acme\MainBundle\Entity\Person');

$person = $person_repo->find(1);
$log = $repo->findBy(array('objectId' => $person->getId()));
foreach ($log as $log_entry) { var_dump($log_entry->getData()); }
Run Code Online (Sandbox Code Playgroud)

但我不明白的是,为什么字段birthdate总是包含在日志条目中,即使它没有改变.这里有一些三个日志条目的例子:

array(9) {
  ["salutation"]=>
  string(4) "Herr"
  ["firstname"]=>
  string(3) "Max"
  ["lastname"]=>
  string(6) "Muster"
  ["street"]=> …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm doctrine-extensions symfony-2.2 stofdoctrineextensions

8
推荐指数
1
解决办法
7029
查看次数

使用可通过api平台软删除的Doctrine扩展

我正在使用Symfony 3.4和api平台构建API。我想在实体上使用软删除。我已经安装DoctrineExtensionsStofDoctrineExtensionsBundle

config.yml

doctrine:
    dbal:
        connections:
            default:
               […]

    orm:
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                connection: default
                mappings:
                    […]
                filters:
                    softdeleteable:
                        class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                        enabled: true
Run Code Online (Sandbox Code Playgroud)

而我的实体:

<?php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * MyEntity
 *
 * @ORM\Table(name="MyEntity", schema="MyEntity")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\MyEntityRepository")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 * @ApiResource
 */
class MyEntity
{
    /**
     * @var \DateTime
     * @ORM\Column(name="deleted_at", type="datetime")
     */
    private $deletedAt;

    […]
Run Code Online (Sandbox Code Playgroud)

这是行不通的。我知道我需要配置一些东西(即EventManager),但我不知道如何做。这是我尝试创建实体时遇到的错误

Listener "SoftDeleteableListener" was not added to the EventManager!

我认为我已经完成了该页面说明的所有内容: …

soft-delete symfony doctrine-extensions api-platform.com

7
推荐指数
1
解决办法
933
查看次数

如何记录具有集合的实体?

我想记录实体的所有更改.我查看了由StofDoctrineExtensionsBundle提供的Loggable教义扩展.

我让它适用于存储简单数据的字段,例如字符串和整数.但我的实体也与另一个实体有许多关系,例如Tags.

我收到此错误:

InvalidMappingException: Cannot versioned [tags] as it is collection in object - Hn\AssetDbBundle\Entity\Asset
Run Code Online (Sandbox Code Playgroud)

有没有办法记录实体与其关系?我不介意切换到另一个捆绑.

symfony doctrine-orm doctrine-extensions stofdoctrineextensions symfony-2.4

6
推荐指数
1
解决办法
1255
查看次数

通过作曲家安装时,gedmo/doctrine-extensions 要求提供令牌

是否还有其他人在通过 Composer 安装 gedmo/doctrine-extensions 时遇到问题?

存储库是公开的,所以我不确定为什么说它是私有存储库

Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+computername+2015-09-04+1040 to retrieve a token. It will be stored in "/location/.composer/auth.json" for future use by Composer. Token (hidden):

github composer-php doctrine-extensions

6
推荐指数
1
解决办法
3080
查看次数

Symfony 3 实体的自定义 JSON 序列化程序

我有一个使用Doctrine's Translatable extension的 Symfony 3.2 实体。

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * Media
 *
 * @ORM\Table(name="medias")
 * @Gedmo\TranslationEntity(class="AppBundle\Entity\Translation\MediaTranslation")
 */
class Media implements Translatable
{
    /* [...] */
    
    /**
     * @var string|null
     *
     * @ORM\Column(type="text", nullable=true)
     * @Gedmo\Translatable
     * @Groups({"single_media"})
     */
    private $description;

    /* [...] */
}
Run Code Online (Sandbox Code Playgroud)

我知道如何使用基本方法在 JSON 中序列化这个实体(我friendsofsymfony/rest-bundle用于 REST API 的序列化),但我想以这样的自定义方式序列化它......

{
    "description": {
        "fr": "description en français",
        "en": "english description",
    }
}
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm doctrine-extensions symfony-3.2

6
推荐指数
1
解决办法
522
查看次数

Zend Framework 2 + Doctrine Extensions Taggable

我正在尝试将DoctrineExtension-Taggable集成到Zend Framework 2.首先我添加到作曲家:

"anh/doctrine-extensions-taggable": "1.1.*@dev"
Run Code Online (Sandbox Code Playgroud)

然后通过服务管理器构建实例(在module.config.php中):

'service_manager' => array(
    'factories' => array(
        'taggableManager' => function($sm) {
            $entityManager = $sm->get('Doctrine\ORM\EntityManager');
            return new \Anh\Taggable\TaggableManager($entityManager, '\Anh\Taggable\Entity\Tag', '\Anh\Taggable\Entity\Tagging');
        },
       'taggableSubscriber' => function($sm) {
            $taggableManager = $sm->get('taggableManager');
            return new \Anh\Taggable\TaggableSubscriber($taggableManager);                                      
        },
    ),
 ),
Run Code Online (Sandbox Code Playgroud)

创建实例后,我在EventManager中注册了订阅者:

'doctrine' => array(
    'driver' => array(
        // standart code for driver initialization
    ),
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'taggableSubscriber',
            ),
        ),
    ),
),
Run Code Online (Sandbox Code Playgroud)

这就是我所做的一切.但是在这一步我有一个错误

致命错误:在/ var/www/html/fryday/vendor/zendframework/zendframework/library/Zend中找到了消息'Zend\ServiceManager\Exception\CircularDependencyFoundException',带有消息'LazyServiceLoader的循环依赖关系,例如Doctrine\ORM\EntityManager'第946行的/ServiceManager/ServiceManager.php

我做错了什么?

php tagging doctrine-orm zend-framework2 doctrine-extensions

5
推荐指数
0
解决办法
304
查看次数

Symfony2:如何在没有表单的情况下验证UploadedFile?

我需要将下载文件从 URL上传到我的服务器,并使用Uploadable (DoctrineExtensions)保留它。几乎一切都很好,我的方法是:

  1. 将文件下载curl到我的服务器上的临时文件夹
  2. 创建UploadedFile方法并用属性值填充它
  3. 将其插入可上传实体Media
  4. 进行验证
  5. 坚持并冲洗

简化的代码:

// ... download file with curl

// Create UploadedFile object
$fileInfo = new File($tpath);
$file = new UploadedFile($tpath, basename($url), $fileInfo->getMimeType(), $fileInfo->getSize(), null);

// Insert file to Media entity
$media = new Media();
$media = $media->setFile($file);
$uploadableManager->markEntityToUpload($media, $file);

// Validate file (by annotations in entity)
$errors = $validator->validate($media);

// If no errors, persist and flush
if(empty($errors)) {
    $em->persist($this->parentEntity);
    $em->flush();
}
Run Code Online (Sandbox Code Playgroud)

如果我跳过验证,则一切正常。文件已成功移动到正确的路径(由 config.yml 中的可上传扩展配置)并保存到数据库。但手动创建的验证 …

validation symfony doctrine-extensions doctrine-uploadable

5
推荐指数
1
解决办法
1259
查看次数