2017-12-02 6 views
0

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!

+0

Ihre Ladefunktion sollte öffentlich sein. – ccKep

+0

Rechts. Ich habe das behoben, aber immer noch den gleichen Fehler wie zuvor – ampher911

+0

Sie haben auch einen Tippfehler in "Persistance", es heißt "Persistence": 'Verwenden Sie Doctrine \ Common \ Persistence \ ObjectManager;' – ccKep

Antwort

1

den Funktionsaufruf von Ihrer Fehlermeldung Grabbing offenbart Ihre Fehler:

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

Die 2 Erklärungen sind:

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

Sie Persistence in Ihrer use Aussage falsch geschrieben.

+0

Das war mein Fehler. Vielen Dank für Ihre Hilfe! – ampher911

Verwandte Themen