2017-07-09 87 views
1

我正在嘗試做我的第一個DAO與Doctrine做一個列表方法。我的實體類是Canales.php在/ src目錄/模型/ DTO文件夾學說。類XXX不是一個有效的實體或映射的超類

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; 
    } 
} 

這個類是產生利用這些線

供應商/斌/學說ORM:轉換映射--from數據庫的XML配置/ XML/

供應商/斌/學說的ORM:生成實體--generate的註解=真--regenerate實體=真正的src/

吾道類(在/ src目錄/模型/ DAO文件夾)

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); 
    } 
} 

}

我的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); 

和我的test.php的文件

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

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

的composer.json是這個

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

當我執行它,我有這個錯誤

致命錯誤:帶消息「Class」model \ dto \ Canales的未捕獲異常「Doctrine \ ORM \ Mapping \ MappingException」不是有效的實體或映射的超類。在/Applications/MAMP/htdocs/yoga/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:336

我曾嘗試在計算器一些類似的問題都沒有結果我。任何想法或建議?

+0

我已經放棄了eAcclerator的一個問題,因爲我在某些答案中得到了答案,因爲我沒有使用它。任何意見,將不勝感激 – barthuin

+0

我已經解決了我的問題。我不得不改變我的bootstrap.php,這一行$ config = Setup :: createAnnotationMetadataConfiguration(array(__ DIR __。「/ src/model/dto」),$ isDevMode,null,null,false); – barthuin

回答

0

我解決了我的問題。我不得不改變我的bootstrap.php,這條線

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