Ich bin Anfänger mit Symfony 2 (2.8. * Version). Ich versuche, Beispieldaten mit Fixture und Faker in meine Datenbank zu laden. Ich habe src/AppBundle/DataFixtures/ORM-Verzeichnis erstellt und legte dort eine LoadPostData.php Datei mit diesem Code:Symfony 2 - konnte keine Fixture laden
<?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();
}
}
Aber wenn ich traf einen Befehl "php app/console Lehre: Leuchten: load" in meinem Terminal ich diesen Fehler:
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
(Linie 10 ist eine Erklärung von Loadpostdata-Klasse)
Was kann ich tun, ist hier falsch? Ich habe ein Tutorial Schritt für Schritt verfolgt und habe keine Ahnung, was fehlt. Danke im Voraus!
Ihre Ladefunktion sollte öffentlich sein. – ccKep
Rechts. Ich habe das behoben, aber immer noch den gleichen Fehler wie zuvor – ampher911
Sie haben auch einen Tippfehler in "Persistance", es heißt "Persistence": 'Verwenden Sie Doctrine \ Common \ Persistence \ ObjectManager;' – ccKep