phpormdoctrinemappedsuperclass

Doctrine. Class XXX is not a valid entity or mapped super class


I'm trying to do my first DAO with Doctrine for doing a list method. My entity class is Canales.php in /src/model/dto folder

namespace model\dto;

use Doctrine\ORM\Mapping as ORM;

/**
 * Canales
 *
 * @ORM\Table(name="Canales")
 * @ORM\Entity
 */
class Canales
{
    /**
     * @var string
     *
     * @ORM\Column(name="Nombre", type="string", length=255, nullable=false)
     */
    private $nombre;

    /**
     * @var integer
     *
     * @ORM\Column(name="Id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * Class Constructor
     * @param    $nombre   
     * @param    $id   
     */
    public function __construct($nombre, $id)
    {
        $this->nombre = $nombre;
        $this->url = $url;
        $this->imagen = $imagen;
        $this->ingles = $ingles;
        $this->id = $id;
    }



    /**
     * Set nombre
     *
     * @param string $nombre
     * @return Canales
     */
    public function setNombre($nombre)
    {
        $this->nombre = $nombre;

        return $this;
    }

    /**
     * Get nombre
     *
     * @return string 
     */
    public function getNombre()
    {
        return $this->nombre;
    }

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

This class was generate using these lines

vendor/bin/doctrine orm:convert-mapping --from-database xml config/xml/

vendor/bin/doctrine orm:generate-entities --generate-annotations=true --regenerate-entities=true src/

my Dao class (in /src/model/dao folder)

class daoGenerico{
private $entityManager;

/**
 * Class Constructor
 * @param    $entityManager   
 */
public function __construct()
{
    require_once("bootstrap.php");
    $this->entityManager = $entityManager;
}


/**
 * @return mixed
 */
public function getEntityManager()
{
    return $this->entityManager;
}

function showAction(){
    $repository = $this->getEntityManager()->getRepository('model\dto\Canales');
        //->find($id);
    echo "..";
    $productos = $repository->findAll();
    echo "OK";
    if (!$productos) {
        throw $this->createNotFoundException(
            'No product found'
        );
    }
    else{
        var_dump($productos);
    }
}   

}

My bootstrap.php

// bootstrap.php

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

require_once "vendor/autoload.php";

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/model/dto"), $isDevMode);

// database configuration parameters
$conn = array(
    'driver'   => 'pdo_mysql',
    'host'     => 'localhost',
    'user'     => 'root',
    'password' => 'root',
    'dbname'   => 'yoga',
    'charset'  => 'UTF8',
);

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);

and my test.php file

include_once('./src/model/dao/daoGenerico.php');

$daoGenerico = new daoGenerico();
$daoGenerico->showAction();

The composer.json is this

{
   "require": {
        "doctrine/orm": "2.4.*"
    },
    "autoload": {
        "psr-0": {"": "src/"}
    }
}

When I executed it, I have this error

Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class "model\dto\Canales" is not a valid entity or mapped super class.' in /Applications/MAMP/htdocs/yoga/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:336

I have tried some similar questions in stackoverflow without results for me. Any idea or advice?


Solution

  • I have resolved my problem. I had to change my bootstrap.php, this line

    $config = Setup::createAnnotationMetadataConfiguration(array(DIR."/src‌​/model/dto"), $isDevMode, null, null, false);