Home Ask Login Register

Developers Planet

Your answer is one click away!

Bartosz February 2016

Symfony 2 - the entity class was not found in the chain configured namespaces

I am trying to implement an internet application using Symfony 2 Framework. I created the entity class, which class I instantiated in the controller and I fullfilled the variables of that class with the data - it worked, but when I tried to send that data to the database - it failed (for some reasons, the persist method failed - of which I got to know because I placed the persist method in the try-catch() block of code).

In the Web browser I received the informaction as below:

string 'The class 'AppBundle\Entity\Practice_Words' was not found in the 
chain configured namespaces ' (length=93)

Code of the Controller:

<?php

  namespace AppBundle\Controller;

  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use AppBundle\Entity\Practice_Words;

  class DefaultController extends Controller
  {
  /**
   * @Route("/", name="homepage")
   */


   public function indexAction()
   {

    $practiceWords = new Practice_Words();
    $practiceWords->setEnglishWord("kind");
    $practiceWords->setPolishWord("rodzaj");

    $em = $this->getDoctrine()->getManager();

    try{
    $em->persist($practiceWords);
    $em->flush();
    }catch(\Exception $e) {
        var_dump($e->getMessage());
    }

    return $this->render('AppBundle:Default:index.html.twig');
   }
 }

Entity - Practice_Words:

<?php

  namespace AppBundle\Entity;

 /**
  * Practice_Words
  */
 class Practice_Words
 {
 /**
  * @var int
  */
     private $id;

 /**
  * @var string
  */
     private $englishWord;

/**
 * @var string
 */
    private $polishWord;

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set englishWord
 *
 * @param string $englishWord
 *
 * @return Practice_Words
 */

public function setEnglishWord($englishW        

Answers


Ozz Mium February 2016

I think the problem could be in your class naming. According to PSR-4 Class names must be wrote down in CamelCase. And for doctrine your class 'AppBundle\Entity\Practice_Words' => 'AppBundle\Entity\Practice\Words.php' Try renaming your class and check your database table names.

Post Status

Asked in February 2016
Viewed 3,766 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life