Symfony 2.*, doctrine:fixtures:load givesPHP Fatal error: class not found

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    #1

    Symfony 2.*, doctrine:fixtures:load givesPHP Fatal error: class not found

    I am following course:
    https://www.udemy.com/introduction-to-web-development-with-symfony2/#/lecture/933870
    Lecture 38.

    In short, they explain how to create Blog website.
    There are Model and Core bundles.
    There are Author and Post entities in Model bundle (Author and Post controllers in Core bundle).

    I have successfully created slug column in Author table with doctrine:migrat ions:diff and doctrine:migrat ions:migrate.
    But i can not generate slug contents, because command:
    doctrine:fixtur es:load gives a PHP fatal error:
    "PHP Fatal error: Class 'Blog\Model\Bun dle\Repository\ AuthorRepositor y' not foun
    d in C:\Bitnami\wamp stack-5.4.38-0\sym_prog\mypr oject\vendor\do ctrine\orm\lib\ Do
    ctrine\ORM\Repo sitory\DefaultR epositoryFactor y.php on line 75"


    I have compared four related (from my point of view) Author files :
    1) src\Blog\ModelB undle\Entity\Au thor.php
    2) src\Blog\CoreBu ndle\Controller \AuthorControll er.php
    3) src\Blog\ModelB undle\Repositor y\AuthorReposit ory.php
    4) src\Blog\ModelB undle\DataFixtu res\ORM\10-Authors.php

    with files provided at the end of the course. There is no difference. I also compared them with Post files, i mean i checked the namespaces i import - again i import and use the adequate namespace as in Post, where slugs were created successfully.

    What are other files which doctrine:fixtur es:load touch? Where i should search for mistake?
  • gintare
    New Member
    • Mar 2007
    • 103

    #2
    Using information from
    http://www.sitepoint.com/data-fixtures-symfony2/

    I figured that command:
    php app/console doctrine:fixtur es:load

    loads fixtures from file "your project root/src/your bundle namespace/DataFixtures/ORMĖ.

    In my case, the directory and file is "C:\Bitnami\wam pstack-5.4.38-0\sym_prog\mypr oject\src\Blog\ ModelBundle\Dat aFixtures\ORM\1 0-Authors.php"

    The file contents:

    Code:
    <?php
    
    namespace Blog\ModelBundle\DataFixtures\ORM;
    
    use Blog\ModelBundle\Entity\Author;
    use Doctrine\Common\DataFixtures\AbstractFixture;
    use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
    use Doctrine\Common\Persistence\ObjectManager;
    
    /**
     * Fixtures for the Author Entity
     */
    
    class Authors extends AbstractFixture implements OrderedFixtureInterface
    {
        /**
         * {@inheritDoc}
         */
        public function getOrder()
        {
            return 10;
        }
    
        /**
         * {@inheritDoc}
         */
        public function load(ObjectManager $manager)
        {
            $a1 = new Author();
            $a1->setName('David');
    
            $a2 = new Author();
            $a2->setName('Eddie');
    
            $a3 = new Author();
            $a3->setName('Elsa');
    
            $manager->persist($a1);
            $manager->persist($a2);
            $manager->persist($a3);
    
            $manager->flush();
        }
    }
    Where can be the mistake, which gives PHP Fatal error: class not found?

    What are other files, which are touches by doctrine:fixtur es:load ? I.e., where i should search for a mistake?

    Comment

    • gintare
      New Member
      • Mar 2007
      • 103

      #3
      The error was in file:
      C:\Bitnami\wamp stack-5.4.38-0\sym_prog\mypr ojec\src\Blog\M odelBundle\Enti ty\Author.php

      Instead of line:
      @ORM\Entity(rep ositoryClass="B log\Model\Bundl e\Repository\Au thorRepository" )

      It should be only: @ORM\Entity()
      or @ORM\Entity(rep ositoryClass="B log\ModelBundle \Repository\Aut horRepository")

      There was misspelling mistake Model\Bundle instead of ModelBundle

      Comment

      Working...