2017-07-11 6 views
0

私はmysqlデータベースに挿入しようとしています。私はdoctrineとstandarのPHP(フレームワークなし)を使用しています。私は彼らの3つのPHPクラスDoctrine Uncaught exception 'ReflectionException'メッセージ 'Class XXXが存在しません'

<?php 

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 string 
* 
* @ORM\Column(name="URL", type="string", length=255, nullable=false) 
*/ 
private $url; 

/** 
* @var string 
* 
* @ORM\Column(name="imagen", type="string", length=255, nullable=false) 
*/ 
private $imagen; 

/** 
* @var boolean 
* 
* @ORM\Column(name="Ingles", type="boolean", nullable=false) 
*/ 
private $ingles; 

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

... 
} 

<?php 

namespace model\dto; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Playlist 
* 
* @ORM\Table(name="playlist", indexes={@ORM\Index(name="idCanal", columns={"idCanal"})}) 
* @ORM\Entity 
*/ 
class Playlist 
{ 

/** 
* @var string 
* 
* @ORM\Column(name="idYoutube", type="string", length=34, nullable=false) 
*/ 
private $idYoutube; 

/** 
* @var string 
* 
* @ORM\Column(name="descripcion", type="string", length=255, nullable=false) 
*/ 
private $descripcion; 

/** 
* @var boolean 
* 
* @ORM\Column(name="ingles", type="boolean", nullable=false) 
*/ 
private $ingles; 

/** 
* @var string 
* 
* @ORM\Column(name="titulo", type="string", length=255, nullable=false) 
*/ 
private $titulo; 

/** 
* @var string 
* 
* @ORM\Column(name="imagen", type="string", length=255, nullable=false) 
*/ 
private $imagen; 

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

/** 
* @var \Canales 
* 
* @ORM\ManyToOne(targetEntity="Canales") 
* @ORM\JoinColumns({ 
* @ORM\JoinColumn(name="idCanal", referencedColumnName="Id") 
* }) 
*/ 
private $idcanal; 
... 
} 

<?php 

namespace model\dto; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Videos 
* 
* @ORM\Table(name="videos", indexes={@ORM\Index(name="idPlaylist", columns={"idPlaylist"})}) 
* @ORM\Entity 
*/ 
class Videos 
{ 

/** 
* @var string 
* 
* @ORM\Column(name="idYoutube", type="string", length=34, nullable=false) 
*/ 
private $idYoutube; 

/** 
* @var string 
* 
* @ORM\Column(name="titulo", type="string", length=255, nullable=false) 
*/ 
private $titulo; 

/** 
* @var string 
* 
* @ORM\Column(name="imagen", type="string", length=255, nullable=false) 
*/ 
private $imagen; 

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

/** 
* @var \Playlist 
* 
* @ORM\ManyToOne(targetEntity="Playlist") 
* @ORM\JoinColumns({ 
* @ORM\JoinColumn(name="idPlaylist", referencedColumnName="idPlaylist") 
* }) 
*/ 
private $idplaylist; 

... 
} 

を持つ3つのテーブルはまた、私はこのDAOを持っているインサートと、クエリ

<?php 

abstract class daoGenerico{ 

private $entityManager; 

/** 
* Class Constructor 
* @param $entityManager 
*/ 
public function __construct() 
{ 
    require("bootstrap.php"); 

    $this->entityManager = $entityManager; 
} 


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

function listAll($nombre){ 
    $repositorio = 'model\dto\\'.$nombre; 
    $repository = $this->getEntityManager()->getRepository($repositorio); 

    $entityList = $repository->findAll(); 

    if (!$entityList) { 
     throw $this->createNotFoundException(
      'No product found' 
     ); 
    } 
    return $entityList; 
} 

function findByIdYoutube($nombre, $entity){ 
    $existe = true; 
    $repositorio = 'model\dto\\'.$nombre; 
    $repository = $this->getEntityManager()->getRepository($repositorio); 

    $entity = $repository->findOneBy(array('idYoutube' => $entity->getIdYoutube())); 

    return $entity; 
} 

function insert($entity){ 
    $entityM= $this->getEntityManager(); 

    $entityM->merge($entity); 
    $entityM->flush(); 
} 

} 
?> 

のために私test.phpをはとき私の問題のocurrsこの

<?php 
function getPlaylists($idCanal) { 

    $key = 'XXXX'; 
    $channel = $idCanal; //ejemplo: UCL-aihy3UD61TmvCOL9szUw 

    $url = "https://www.googleapis.com/youtube/v3/playlists?key=$key&channelId=$channel&part=snippet,id&order=date&maxResults=50"; 

    $json = file_get_contents($url); 

    $obj = json_decode($json, true); 

    //var_dump($obj); 

    return $obj; 
} 

function getVideosByPlaylists($idPlaylist) { 

    $key = 'XXXXX'; 

    $url = "https://www.googleapis.com/youtube/v3/playlistItems?key=$key&playlistId=$idPlaylist&part=snippet,id&order=date&maxResults=50"; 

    $json = file_get_contents($url); 

    $obj = json_decode($json, true); 

    //var_dump($obj); 

    return $obj; 
} 

include_once('./src/model/dao/daoGenerico.php'); 
include_once('./src/model/dao/daoCanal.php'); 
include_once('./src/model/dao/daoPlaylist.php'); 
include_once('./src/model/dao/daoVideo.php'); 
include_once('./src/model/dto/Playlist.php'); 
include_once('./src/model/dto/Videos.php'); 

$daoCanal = new daoCanal(); 
$daoPlaylist = new daoPlaylist(); 
$daoVideo = new daoVideo(); 
$canales = $daoCanal->listAll('Canales'); 

foreach ($canales as $canal) { 
    echo ($canal->getNombre()."\n"); 

    //buscamos las playlist del canal 
    $playlistsYT = getPlaylists($canal->getUrl()); 

    foreach ($playlistsYT['items'] as $playlistYT) { 

     //obtenemos los valores y buscamos en BD si ya existe esa playlist 
     $idcanal = $canal; 
     $idYoutube = $playlistYT["id"]; 
     $titulo = $playlistYT["snippet"]["title"]; 
     $descripcion = $playlistYT["snippet"]["description"]; 
     $imagen = $playlistYT["snippet"]["thumbnails"]["high"]["url"]; 
     $ingles = $canal->getIngles(); 

     $playlist = new model\dto\Playlist($idYoutube, $descripcion, $ingles, $titulo, $imagen, $idcanal); 

     $playlistBD = $daoPlaylist->findByIdYoutube('Playlist',$playlist); 

     if(!$playlistBD){ 
      //si no existe, se crea 
      echo ("-->".$playlist->getTitulo()."\n"); 
      $daoPlaylist->insert($playlist); 
      $playlistBD = $daoPlaylist->findByIdYoutube('Playlist',$playlist); 
     } 
     //actualizamos el objeto $playlist para guardar el id generado 
     $playlist->setId($playlistBD->getId()); 

     //buscamos los videos correspondientes a esa playlist 
     $videosYT = getVideosByPlaylists($playlist->getidYoutube()); 

     foreach ($videosYT['items'] as $videoYT) { 

      //obtenemos los valores 
      $idPlaylist = $playlist; 
      $idYoutube = $videoYT["snippet"]["resourceId"]["videoId"]; 
      $titulo = $videoYT["snippet"]["title"]; 

      //si el video no tiene thumbnails, es que ha sido eliminado o es privado 
      if(isset($videoYT["snippet"]["thumbnails"])){ 
       $imagen = $videoYT["snippet"]["thumbnails"]["high"]["url"]; 

       $video = new model\dto\Videos($idYoutube, $titulo, $imagen, $idPlaylist); 

       //buscamos en BD si ya existe ese video 
       $existe = $daoVideo->findByIdYoutube('Videos',$video); 
       var_dump($video); 
       if(!$existe){ 
        echo ("-->".$video->getTitulo()."\n"); 
        $daoVideo->insert($video); 
       } 
      } 
     } 
    } 
} 
?> 

ですこの行が実行されます

$ daoVideo-> insert($ video) ;

プレイリストのステップに挿入してクエリし、ビデオステップではクエリできますが、挿入するビデオは挿入できません。これはエラーです

Fatal error: Uncaught exception 'ReflectionException' with message 'Class Canales does not exist' in /Applications/MAMP/htdocs/yoga/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php:960 
Stack trace: 
#0 /Applications/MAMP/htdocs/yoga/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php(960): ReflectionParameter->getClass() 
#1 /Applications/MAMP/htdocs/yoga/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php(908): Doctrine\Common\Proxy\ProxyGenerator->getParameterType(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(ReflectionMethod), Object(ReflectionParameter)) 
#2 /Applications/MAMP/htdocs/yoga/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php(780): Doctrine\Common\Proxy\ProxyGenerator->buildParametersString(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(ReflectionMethod), Array) 
#3 [internal function]: Doctrine\Common\Proxy\ProxyGenerator->generateMethods(Object(Doctrine\ORM\Mapping\ClassMetadata)) 
#4 /Applications/MAMP/htdocs/yoga/vendor/doctrine/c in /Applications/MAMP/htdocs/yoga/vendor/doctrine/common/lib/Doctrine/Common/Proxy/Exception/UnexpectedValueException.php on line 57 

このエラーに関するお問い合わせはこちら?

ありがとうございました

+0

:私のクラスでは、setCanalはこの

ように私はこのためにそれを変更しなければなりませんでした。私のクラスでは、setCanalはこのpublic function setIdcanal(Canales $ idcanal = null)のようでした。私はこれのためにそれを変更しなければなりません:public function setIdcanal(\ model \ dto \ Canales $ idcanal = null) – barthuin

答えて

0

私は解決策を見つけました。私は解決策を見つけた

public function setIdcanal(\model\dto\Canales $idcanal = null) {  
... 
} 
関連する問題