How to create a new model with Sylius via SyliusResourceBundle

I found and successfully used the documentation on how to override an existing model in Sylius, but I was not able to create a completely new one using SyliusResourceBundle. Im guessing this easy if you already know symfony2? I'm still participating, so here is what I have ... what am I missing?

I use the full complete installation of Sylius as my base, so I started here http://sylius.org/blog/simpler-crud-for-symfony2 I have my own "Astound Bundle", settings and several overrides and controllers. I added this to my configuration:

sylius_resource:
    resources:
        astound.location:
            driver: doctrine/orm
            templates: AstoundWebBundle:Location
            classes:
                model: Astound\Bundle\LocationBundle\Model\Location

Then I did:

<?php

namespace Astound\Bundle\LocationBundle\Model;

class Location implements LocationInterface
{
    /**
     * @var mixed
     */
    protected $id;

    /**
     * @var string
     */
    protected $name;

    public function getId()
    {
        return $this->id;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * {@inheritdoc}
     */
    public function setName($name)
    {
        $this->name = $name;
    }
}

As well as:

<?php

namespace Astound\Bundle\LocationBundle\Model;


interface LocationInterface
{
    /**
     * Get Id.
     *
     * @return string
     */
    public function getId();

    /**
     * Get name.
     *
     * @return string
     */
    public function getName();

    /**
     * Set name.
     *
     * @param string $name
     */
    public function setName($name);
}

Based on exploring existing models in Sylius and looking at the Doctrine documentation, I did this as well:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Astound/Bundle/LocationBundle/Resources/config/doctrine/model/Location.orm.xml -->
<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://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

      <mapped-superclass name="Location" table="Locations">
          <id name="id" type="integer">
              <generator strategy="AUTO" />
          </id>

          <field name="name" type="string" />
      </mapped-superclass>
</doctrine-mapping>

, app/console doctrine: schema: update --dump-sql "Locations" , :

- .

app/console: debug, :

astound.controller.location
Sylius\Bundle\ResourceBundle\Controller\ResourceController

astound.manager.location
n/a doctrine.orm.default_entity_manager

astound.repository.location
Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository

, indexAction . :

astound_location_index:
    pattern: /location
    methods: [GET]
    defaults:
        _controller: astound.controller.location:indexAction

, * app_dev.php/Administration/location * , :

"Astound\Bundle\LocationBundle\Model\Location"

, , http://brentertainment.com/other/docs/book/doctrine/orm.html, , php- Entities /: : " "?, Sylius Entity , - ... , Bundle? , Sylius, :

<?php

namespace Astound\Bundle\LocationBundle;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\ResolveDoctrineTargetEntitiesPass;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
 * Astound LocationBundle
 */

class AstoundLocationBundle extends Bundle
{
    /**
     * Return array with currently supported drivers.
     *
     * @return array
     */
    public static function getSupportedDrivers()
    {
        return array(
            SyliusResourceBundle::DRIVER_DOCTRINE_ORM
        );
    }

    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container)
    {
        $interfaces = array(
            'Astound\Bundle\LocationBundle\Model\LocationInterface'         => 'astound.model.location.class',
        );

        $container->addCompilerPass(new ResolveDoctrineTargetEntitiesPass('astound_location', $interfaces));

        $mappings = array(
            realpath(__DIR__ . '/Resources/config/doctrine/model') => 'Astound\Bundle\LocationBundle\Model',
        );

        $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, array('doctrine.orm.entity_manager'), 'astound_location.driver.doctrine/orm'));
    }
}

:

NotFoundException: "astound_location.driver".

:

astound_location:
    driver: doctrine/orm

:

FileLoaderLoadException: ".../app/config/astound.yml" "...//Config/config.yml". ( , "astound_location" (...//Config/astound.yml). "Astound_location"

, ! ?! ?

+4
1

, .. /, Sylius. , sylius_resource. "Nothing to update" doctrine: schema: update.

, , " ", Sylius, " " "", .

, , " " "". . :

: : Astound\Bundle\LocationBundle\Model\

: Astound\Bundle\LocationBundle\Entity\

: mapped-superclass name= "Location" table = "Locations"

entity name= "Location" table = "Locations"

( sylius , , , ), sylius .

" " SyliusResourceBundle, .

0

Source: https://habr.com/ru/post/1530329/


All Articles