簡體   English   中英

Symfony 2-無法加載燈具

[英]Symfony 2 - couldn't load a fixture

我是Symfony 2(2.8。*版本)的初學者。 我正在嘗試使用fixture和fakerr將樣本數據加載到數據庫中。 我創建了src / AppBundle / DataFixtures / ORM目錄,並在其中放置了一個帶有以下代碼的LoadPostData.php文件:

<?php

namespace AppBundle\DataFixtures\ORM;


use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistance\ObjectManager;


class LoadPostData implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $faker = \Faker\Factory::create();

        for ($i = 1; $i < 200; $i++) {

            $post = new \AppBundle\Entity\Post();
            $post->setTitle($faker->sentence(3));
            $post->setLead($faker->text(300));
            $post->setContent($faker->text(800));
            $post->setCreatedAt($faker->dateTimeThisMonth);


            $manager->persist($post);
        }


        $manager->flush();
    }
}

但是,當我在終端中點擊命令“ php app / console doctrine:fixtures:load”時,出現此錯誤:

PHP Fatal error:  Declaration of AppBundle\DataFixtures\ORM\LoadPostData::load(Doctrine\Common\Persistance\O
bjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Common\Persist
ence\ObjectManager $manager) in /Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/
LoadPostData.php on line 10

Fatal error: Declaration of AppBundle\DataFixtures\ORM\LoadPostData::load(Doctrine\Common\Persistance\ObjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Common\Persistence\ObjectManager $manager) in /Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/LoadPostData.php on line 10

(第10行是LoadPostData類的聲明)

我在這里做什么錯? 我一步一步地按照教程學習,不知道缺少了什么。 提前致謝!

從錯誤消息中抓住函數調用可以發現您的錯誤:

致命錯誤:AppBundle \\ DataFixtures \\ ORM \\ LoadPostData :: load(Doctrine \\ Common \\ Persistance \\ ObjectManager $ manager)的聲明必須與Doctrine \\ Common \\ DataFixtures \\ FixtureInterface :: load(Doctrine \\ Common \\ Persistence \\ ObjectManager $ manager兼容) )在第10行的/Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/LoadPostData.php中

這兩個聲明是:

::load(Doctrine\Common\Persistance\ObjectManager $manager)
::load(Doctrine\Common\Persistence\ObjectManager $manager)

您在use語句中拼寫了Persistence

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM