symfony 2(2.8。*バージョン)の初心者です。フィクスチャとfakerを使用してサンプルデータをデータベースにロードしようとしています。私はSRC/AppBundle/DataFixtures/ORMのディレクトリを作成し、このコードでLoadPostData.phpファイルをそこに入れている:Symfony 2 - Fixtureを読み込めませんでした
<?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アプリ/コンソール教義ロード」を打ったときに、私のターミナル私はこのエラーを取得する:私はここで間違って
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クラスの宣言です)
何をしますか?私はチュートリアルのステップを踏んでいて何が欠けているのか分かりませんでした。前もって感謝します!あなたのuse
文でPersistence
をスペルミス
::load(Doctrine\Common\Persistance\ObjectManager $manager)
::load(Doctrine\Common\Persistence\ObjectManager $manager)
:
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
2つの宣言がされて:
あなたの 'load'関数はpublicでなければなりません。 – ccKep
右。私はそれを修正しましたが、以前と同じエラーが表示されます – ampher911
"Persistance"の入力ミスがあります。 "Persistence"と呼ばれています:Doctrine \ Common \ Persistence \ ObjectManager;を使用してください – ccKep