Symfony 4-在夹具中加载YML文件

时间:2018-07-12 15:03:05

标签: php doctrine symfony4 fixture

我希望获得有关Symfony 4.1特定主题的帮助。 我想加载一些存储在YML文件中的数据以使用灯具。 为了加载此文件,我使用了依赖项注入,但我不明白为什么未达到加载功能。

这是我的下面的代码:

AppExtension:

<?php

namespace App\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
 * This is the class that validates and merges configuration from your app/config files.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('app');

        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        return $treeBuilder;
    }
}

Configuration.php:

<?php
namespace App\DataFixtures\ORM;

use Doctrine\Common\Persistence\ObjectManager;
use App\Entity\Patient;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Symfony\Component\DependencyInjection\ContainerInterface;


class LoadPatientData extends Fixture {
    /**
     *
     * @var ContainerInterface
     */
    private $container;


    public function __construct(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function load(ObjectManager $manager)
    {
        //var_dump($this->container)

        $patientsArray = $this->container->getParameter('Patient');

        foreach( $patientsArray as $name => $object )
        {
            $patient = new Patient();

            foreach( $object as $key => $value )
            {
                $patient->{$key}($value);
            }

            $manager->persist($patient);
            $this->addReference($name, $patient);
        }
        $manager->flush();
    }

}

关于固定装置:

pos = np.random.sample((1000, 3))
pos_data = xr.DataArray(pos, dims=('time', 'h_pos'), coords={'h_pos': ['x', 'y', 'z']})

rot = np.random.sample((1000, 3, 3))
rot_data = xr.DataArray(rot, dims=('time', 'h_rot_i', 'h_rot_j'))

这是文件夹树: folders tree

控制台错误: Console error

预先感谢您的帮助。

0 个答案:

没有答案