Sylius Overriding ShopUser模型

时间:2016-11-26 21:01:04

标签: php symfony sylius

我想覆盖SyliusCoreBundle的shop_user模型,我已经跟随instructions,但有2个问题。

  1. 当我使用“sylius_shop_user”作为表名时,在doctrine配置文件中, 它说这个表已经存在。 The table with name 'sylius_dev.sylius_shop_user' already exists.

  2. 当我想覆盖shop_user模型的类时,我收到此错误:Unrecognized option "shop_user" under "sylius_core.resources"

1 个答案:

答案 0 :(得分:2)

这是我对1.0.0-alpha.1的配置:)

sylius_user:
    resources:
        shop:
            user:
                classes:
                    model: AppBundle\Entity\ShopUser
                    repository: AppBundle\Entity\Repository\ShopUserRepository
                    form:
                        default: AppBundle\Form\Type\Api\UserType

sylius_resource:
    resources:
        app.shop_user:
            classes:
                model: AppBundle\Entity\ShopUser
                repository: AppBundle\Entity\Repository\ShopUserRepository
                controller: AppBundle\Controller\Api\UserController

sylius_api:
    resources:
        api_user:
            classes:
                model: "%sylius.model.shop_user.class%"

doctrine:
    orm:
        resolve_target_entities:
            AppBundle\Entity\ShopUserInterface: AppBundle\Entity\ShopUser

ShopUser.php

namespace AppBundle\Entity;

use Sylius\Component\Core\Model\ShopUser as BaseShopUser;

class ShopUser extends BaseShopUser implements ShopUserInterface {...}

ShopUserInterface.php

namespace AppBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Component\Core\Model\ShopUserInterface as BaseShopUserInterface;

interface ShopUserInterface extends BaseShopUserInterface {...}

ShopUserRepository.php

namespace AppBundle\Entity\Repository;

use Sylius\Bundle\CoreBundle\Doctrine\ORM\UserRepository as BaseUserRepository;

class ShopUserRepository extends BaseUserRepository implements ShopUserRepositoryInterface {...}

ShopUserRepositoryInterface.php

namespace AppBundle\Entity\Repository;

use Sylius\Component\User\Repository\UserRepositoryInterface;

interface ShopUserRepositoryInterface extends UserRepositoryInterface {...}

/src/AppBundle/Resources/config/doctrine/ShopUser.orm.xml

<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                             http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\ShopUser" table="sylius_shop_user" repository-class="AppBundle\Entity\Repository\ShopUserRepository">
        ...
    </entity>

</doctrine-mapping>

的src /的appbundle /资源/配置/串行器/ Entity.ShopUser.yml

AppBundle\Entity\ShopUser:
    exclusion_policy: ALL