Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php DataFixture是';t使用nelmio/alice保存(sf 3.3和flex)_Php_Mysql_Symfony - Fatal编程技术网

Php DataFixture是';t使用nelmio/alice保存(sf 3.3和flex)

Php DataFixture是';t使用nelmio/alice保存(sf 3.3和flex),php,mysql,symfony,Php,Mysql,Symfony,您好,我正在使用flex与Symfony合作进行学习。在我安装了一些菜谱之后,我想添加nelmio/alice,以便为doctrine Fixture生成假数据,但是在我加载Fixture之后,没有数据保存到mysql中。知道我做错了什么吗 <?php namespace App\DataFixtures\ORM; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\Persistence\ObjectMan

您好,我正在使用flex与Symfony合作进行学习。在我安装了一些菜谱之后,我想添加nelmio/alice,以便为doctrine Fixture生成假数据,但是在我加载Fixture之后,没有数据保存到mysql中。知道我做错了什么吗

<?php  
namespace App\DataFixtures\ORM;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Nelmio\Alice\Loader\NativeLoader;

class LoadFixtures extends Fixture
{
    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {   
        $loader = new NativeLoader();
        $obj = $loader->loadFile(__DIR__ . 'fixtures.yml');   
    }
bundles.php

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
    Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['all' => true],
];
作曲家

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.0.8",
        "doctrine/doctrine-fixtures-bundle": "^2.4",
        "doctrine/doctrine-migrations-bundle": "^1.2",
        "sensio/framework-extra-bundle": "^5.0",
        "sensiolabs/security-checker": "^4.1",
        "symfony/console": "^3.3",
        "symfony/framework-bundle": "^3.3",
        "symfony/orm-pack": "^1.0",
        "symfony/security-core": "^3.3",
        "symfony/yaml": "^3.3"
    },
    "require-dev": {
        "nelmio/alice": "^3.1",
        "symfony/dotenv": "^3.3",
        "symfony/flex": "^1.0"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
            "security-checker security:check": "script"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*",
        "symfony/twig-bundle": "<3.3",
        "symfony/debug": "<3.3"
    },
    "extra": {
        "symfony": {
            "id": "01BX9RZX7RBK5CNHP741EVCXB5",
            "allow-contrib": false
        }
    }
}
{
“类型”:“项目”,
“许可证”:“专有”,
“要求”:{
“php”:“^7.0.8”,
“条令/条令固定装置包”:“^2.4”,
“条令/条令迁移包”:“^1.2”,
“sensio/framework额外捆绑包”:“^5.0”,
“sensiolabs/安全检查器”:“^4.1”,
“符号/控制台”:“^3.3”,
“symfony/frameworkbundle”:“^3.3”,
“symfony/orm包”:“^1.0”,
“symfony/安全核心”:“^3.3”,
“symfony/yaml”:“^3.3”
},
“需要开发”:{
“nelmio/alice”:“^3.1”,
“symfony/dotenv”:“^3.3”,
“symfony/flex”:“^1.0”
},
“配置”:{
“首选安装”:{
“*”:“距离”
},
“排序包”:true
},
“自动加载”:{
“psr-4”:{
“应用\\\”:“src/”
}
},
“自动加载开发”:{
“psr-4”:{
“App\\Tests\\”:“Tests/”
}
},
“脚本”:{
“自动脚本”:{
“缓存:清除”:“symfony cmd”,
“资产:安装--symlink--相对%PUBLIC_DIR%”:“symfony cmd”,
“安全检查器安全:检查”:“脚本”
},
“安装后命令”:[
“@自动脚本”
],
“更新后命令”:[
“@自动脚本”
]
},
“冲突”:{
“symfony/symfony”:“*”,

“symfony/twig bundle”:“我通过安装TheFidry/alice数据装置解决了这个问题,因为nelmio/alice 3.x似乎与旧版本不一样。(它不再处理数据库查询)

乐: 也许是我的错,但自从SF4正式发布以来,我的加载部分出现了一些问题。 这里有一个补丁供任何人查看 您需要这样的服务来加载设备

App\DataFixtures\ORM\DataFixtures:
    arguments: ['@fidry_alice_data_fixtures.doctrine.purger_loader']
    calls:
        - [load, ['@doctrine.orm.entity_manager']]
    tags: [doctrine.fixture.orm]
在方法上,

    $files = [
        __DIR__ . '/fixtures.yml',
    ];
    $this->loader->load($files);

我当时正试着跟着市场走,却在回购协议上迷路了。这个答案对我很有用

您需要添加回购

添加后 这里有一个快速指南,供所有同样迷路的人参考:

namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DataFixtures extends Controller implements FixtureInterface
{
   public function load(ObjectManager $manager)
   {
    //File Path/s needs to be in array
    $dummyFilePath =[__DIR__.'/DataFixtures.yml'];
    //get fidry loader
    $loader = $this->get('fidry_alice_data_fixtures.doctrine.loader');
    //execute
    $loader->load($dummyFilePath);
   }
}
App\DataFixtures\ORM\DataFixtures:
    arguments: ['@fidry_alice_data_fixtures.doctrine.purger_loader']
    calls:
        - [load, ['@doctrine.orm.entity_manager']]
    tags: [doctrine.fixture.orm]
    $files = [
        __DIR__ . '/fixtures.yml',
    ];
    $this->loader->load($files);
namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DataFixtures extends Controller implements FixtureInterface
{
   public function load(ObjectManager $manager)
   {
    //File Path/s needs to be in array
    $dummyFilePath =[__DIR__.'/DataFixtures.yml'];
    //get fidry loader
    $loader = $this->get('fidry_alice_data_fixtures.doctrine.loader');
    //execute
    $loader->load($dummyFilePath);
   }
}