覆盖 akeneo 实体时出错 [英] error on override akeneo entity

查看:31
本文介绍了覆盖 akeneo 实体时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试覆盖 akeneo 项目的 category 实体.我遵循文档,但总是有一个我无法解决的错误.

I try to override the category entity of an akeneo project. I follow the doc but always have an error i can't resolve.

config.yml

-
    original: Pim\Bundle\CatalogBundle\Entity\Category
    override: MyBundle\CatalogBundle\Entity\Category

entities.yml

parameters:
    pim_catalog.entity.category.class: MyBundle\CatalogBundle\Entity\Category

覆盖,category.php

<?php

namespace MyBundle\CatalogBundle\Entity;

use Pim\Bundle\CatalogBundle\Entity\Category as BaseCategory;

class Category extends BaseCategory
{
    protected $test;

    public function getTest()
    {
        return $this->test;
    }

    public function setTest($test)
    {
        $this->test = $test;

        return $this;
    }
}

category.orm.yml

MyBundle\CatalogBundle\Entity\Category:
    type: entity
    table: pim_catalog_category
    changeTrackingPolicy: DEFERRED_EXPLICIT
    repositoryClass: Akeneo\Bundle\ClassificationBundle\Doctrine\ORM\Repository\CategoryRepository
    uniqueConstraints:
        pim_category_code_uc:
            columns:
                - code
    gedmo:
        tree:
            type: nested
    fields:
        test:
            type: string
            length: 255
            nullable: true

然后在浏览器上我有以下错误:

Then on the browser i have the following error :

UnexpectedValueException in TreeListener.php line 74: Tree object class: Pim\Bundle\CatalogBundle\Entity\Category must have tree metadata at this point

这里是抛出异常的函数,它是gedmo学说扩展的一部分

here is the function that throw the exception, it is part of the gedmo doctrine extensions

 public function getStrategy(ObjectManager $om, $class)
{
    if (!isset($this->strategies[$class])) {
        $config = $this->getConfiguration($om, $class);

        if (!$config) {
            throw new \Gedmo\Exception\UnexpectedValueException("Tree object class: {$class} must have tree metadata at this point");
        }
        $managerName = 'UnsupportedManager';
        if ($om instanceof \Doctrine\ORM\EntityManager) {
            $managerName = 'ORM';
        } elseif ($om instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
            $managerName = 'ODM\\MongoDB';
        }
        if (!isset($this->strategyInstances[$config['strategy']])) {
            $strategyClass = $this->getNamespace().'\\Strategy\\'.$managerName.'\\'.ucfirst($config['strategy']);

            if (!class_exists($strategyClass)) {
                throw new \Gedmo\Exception\InvalidArgumentException($managerName." TreeListener does not support tree type: {$config['strategy']}");
            }
            $this->strategyInstances[$config['strategy']] = new $strategyClass($this);
        }
        $this->strategies[$class] = $config['strategy'];
    }

    return $this->strategyInstances[$this->strategies[$class]];
}

推荐答案

解决方案:

上述问题的发生是由于 DependencyInjection.要解决此问题,请按照以下说明操作:

Solution:

The above issue occurred due to the DependencyInjection. In order to fix this issue follow the below instructions:

1) It has to live in the DependencyInjection namespace of the bundle;
2) It has to implement the ExtensionInterface, which is usually achieved by extending the Extension class;
3) The name is equal to the bundle name with the Bundle suffix replaced by Extension (e.g. the Extension class of the AcmeBundle would be called AcmeExtension and the one for AcmeCatalogBundle would be called AcmeCatalogExtension).

#/src/Acme/Bundle/CatalogBu​​ndle/DependencyInjection/AcmeCatalogExtension.php

<?php

namespace Acme\Bundle\CatalogBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class AcmeCatalogExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('entities.yml');
    }
}

如果您有任何问题,请告诉我

这篇关于覆盖 akeneo 实体时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆