“无法找到Fiche实体”symfony2

“无法找到Fiche实体”symfony2

问题描述:

我想在我的ficheController中添加一个新的函数,该函数根据给定的状态显示文件。这里是控制器代码:“无法找到Fiche实体”symfony2

/** 
* @Route("/mesfiches") 
* @Method("Get") 
* @Template("rexBundle:fiche:mesfiches.html.twig") 
*/ 
public function mesfichesAction() 
{ 
    $em = $this->getDoctrine()->getManager(); 

    $entities = $em->getRepository('rexBundle:fiche') 
     -> findBy(
      array('libEtatFi'=> 'brouillon'), 
      array('id' => 'ASC') 
     ); 

    return array(
     'entities' => $entities, 
    ); 

} 

这在我的树枝代码:

{% extends 'JordiLlonchCrudGeneratorBundle::layout.html.twig' %} 
    {% block body -%} 
    <h1>fiche list</h1> 

    <table class="records_list"> 
    <thead> 
    <tr> 
     <th>Id</th> 
     <th>Titrefiche</th> 
     <th>Dateouv</th> 

    </tr> 
    </thead> 
    <tbody> 
    {% for entity in entities %} 
     <tr> 
      <td><a href="{{ path('fiche_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> 
      <td>{{ entity.titreFiche }}</td> 
      <td>{% if entity.dateOuv %}{{ entity.dateOuv|date('Y-m-d H:i:s') }}{% endif %}</td> 

      <td> 
       <ul> 
        <li> 
         <a href="{{ path('fiche_show', { 'id': entity.id }) }}">Afficher</a> 
        </li> 
        <li> 
         <a href="{{ path('fiche_edit', { 'id': entity.id }) }}">Modifier</a> 
        </li> 
       </ul> 
      </td> 
     </tr> 
    {% endfor %} 
    </tbody> 
</table> 

{% endblock %} 

,最后,这是我的路由配置:

fiche_mesfiches: 
    pattern: /mesfiches 
    defaults: { _controller: rexBundle:fiche:mesfiches } 
    methods: [Get] 

如何删除这个例外? 这是我的缩微胶片实体:

 <?php 

    namespace rex\Bundle\Entity; 

    use Doctrine\ORM\Mapping as ORM; 
    use Symfony\Component\Validator\Constraints as Assert; 
    use Symfony\Component\HttpKernel\DependencyInjection\Extension; 
    use Symfony\Component\HttpFoundation\File\UploadedFile; 
    use Doctrine\Common\Collections\ArrayCollection; 
    use Symfony\Component\Finder\Finder; 

/** 
* fiche 
    * @ORM\Table() 
    * @ORM\Entity(repositoryClass="rex\Bundle\Entity\ficheRepository") 
    * @ORM\HasLifecycleCallbacks 
    */ 

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

/** 
* @var string 
* 
* @ORM\Column(name="titreFiche", type="string", length=255 , nullable= false) 
*/ 
private $titreFiche; 
/** 
* @var string 
* 
* @ORM\Column(name="auteur", type="string", length=255 , nullable= false) 
*/ 
private $auteur; 
/** 
* @param string $auteur 
*/ 
public function setAuteur($auteur) 
{ 
    $this->auteur = $auteur; 
} 

/** 
* @return string 
*/ 
public function getAuteur() 
{ 
    return $this->auteur; 
} 

/** 
* @var \DateTime 
* 
* @ORM\Column(name="dateOuv", type="date", nullable= true) 
*/ 
private $dateOuv; 


/** 
* @var string 
* 
* @ORM\Column(name="observation", type="string", length=100000 , nullable= true) 
*/ 
private $observation; 

/** 
* @var string 
* 
* @ORM\Column(name="cause", type="string", length=100000 , nullable= true) 
*/ 
private $cause; 

/** 
* @var string 
* 
* @ORM\Column(name="solution", type="string", length=100000 , nullable= true) 
*/ 
private $solution; 

/** 
* @var string 
* 
* @ORM\Column(name="comment", type="string", length=100000 , nullable= true) 
*/ 
private $comment; 

/** 
* @var string 
* 
* @ORM\Column(name="confid", type="string" , nullable= true) 
*/ 
private $confid; 

/** 
* @var string 
* 
* @ORM\Column(name="atteinteSecPerso", type="string", nullable= true) 
*/ 
private $atteinteSecPerso; 

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

/** 
* @var string 
* 
* @ORM\Column(name="atteinteSecMat", type="string" , nullable= true) 
*/ 
private $atteinteSecMat; 

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

/** 
* @var string 
* 
* @ORM\Column(name="planAct", type="string", length=100000 , nullable= true) 
*/ 
private $planAct; 

/** 
* @var string 
* 
* @ORM\Column(name="cout", type="string" , nullable= true) 
*/ 
private $cout; 

/** 
* @var string 
* 
* @ORM\Column(name="delai", type="string" , nullable= true) 
*/ 
private $delai; 

/** 
* @var \DateTime 
* 
* @ORM\Column(name="dateMEP", type="date" , nullable= true) 
*/ 
private $dateMEP; 


/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\estimation") 
* @ORM\JoinColumn 
*/ 
private $libEstimat; 

/** 
* @var string 
* @ORM\ManyToMany(targetEntity="rex\Bundle\Entity\processusImpacte") 
* @ORM\JoinColumn 
*/ 
private $libProcess; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\impactDelai") 
* @ORM\JoinColumn 
*/ 
private $valeur; 

/** 
* @param string typeImpD 
*/ 
public function setTypeImpD($typeImpD) 
{ 
    $this->typeImpD = $typeImpD; 
} 


/** 
* @var string 
* 
* @ORM\Column(name="typeImpD", type="string", nullable= true) 
*/ 
private $typeImpD; 

/** 
* @param string $typeImpC 
*/ 
public function setTypeImpC($typeImpC) 
{ 
    $this->typeImpC = $typeImpC; 
} 

/** 
* @return string 
*/ 
public function getTypeImpC() 
{ 
    return $this->typeImpC; 
} 

/** 
* @return string 
*/ 
public function getTypeImpD() 
{ 
    return $this->typeImpD; 
} 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\impactCout") 
* @ORM\JoinColumn 
*/ 
private $montant; 


/** 
* @var string 
* 
* @ORM\Column(name="typeImpC", type="string", nullable= true) 
*/ 
private $typeImpC; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\typeActeur") 
* @ORM\JoinColumn 
*/ 
private $libTypeAct; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\UserBundle\Entity\User") 
* @ORM\JoinColumn 
*/ 
private $nom; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\etatFiche") 
* @ORM\JoinColumn 
*/ 
private $libEtatFi; 

/** 
* @var string 
* @ORM\ManyToMany(targetEntity="rex\Bundle\Entity\origineVal") 
* @ORM\JoinColumn 
*/ 

private $libOrigVal; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\origineInterne") 
* @ORM\JoinColumn 
*/ 

private $libOrigInt; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\etatAction") 
* @ORM\JoinColumn 
*/ 
private $libEtatAc; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\projet") 
* @ORM\JoinColumn 
*/ 
private $libProjet; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\origineExterne") 
* @ORM\JoinColumn 
*/ 
private $libActeur; 

/** 
* @var string 
* @ORM\ManyToMany(targetEntity="rex\Bundle\Entity\motsCles") 
* @ORM\JoinColumn 
*/ 

private $libmot; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\complexite") 
* @ORM\JoinColumn 
*/ 

private $complexite; 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\serviceEmetteur") 
* @ORM\JoinColumn 
*/ 

private $libService; 

/** 
* @param string $libEstimat 
*/ 
public function setLibEstimat($libEstimat) 
{ 
    $this->libEstimat = $libEstimat; 
} 

/** 
* @return string 
*/ 
public function getLibEstimat() 
{ 
    return $this->libEstimat; 
} 


/** 
* @param string $libEtatFi 
*/ 
public function setLibEtatFi($libEtatFi) 
{ 
    $this->libEtatFi = $libEtatFi; 
} 

/** 
* @return string 
*/ 
public function getLibEtatFi() 
{ 
    return $this->libEtatFi; 
} 



/** 
* @param string $libOrigVal 
*/ 
public function setLibOrigVal($libOrigVal) 
{ 
    $this->libOrigVal = $libOrigVal; 
} 

/** 
* @return string 
*/ 
public function getLibOrigVal() 
{ 
    return $this->libOrigVal; 
} 



/** 
* @param string $libOrigInt 
*/ 
public function setLibOrigInt($libOrigInt) 
{ 
    $this->libOrigInt = $libOrigInt; 
} 

/** 
* @return string 
*/ 
public function getLibOrigInt() 
{ 
    return $this->libOrigInt; 
} 



/** 
* @param string $libEtatAc 
*/ 
public function setLibEtatAc($libEtatAc) 
{ 
    $this->libEtatAc = $libEtatAc; 
} 

/** 
* @return string 
*/ 
public function getLibEtatAc() 
{ 
    return $this->libEtatAc; 
} 



/** 
* @param string $libProjet 
*/ 
public function setLibProjet($libProjet) 
{ 
    $this->libProjet = $libProjet; 
} 

/** 
* @return string 
*/ 
public function getLibProjet() 
{ 
    return $this->libProjet; 
} 



/** 
* @param string $libActeur 
*/ 
public function setLibActeur($libActeur) 
{ 
    $this->libActeur = $libActeur; 
} 

/** 
* @return string 
*/ 
public function getLibActeur() 
{ 
    return $this->libActeur; 
} 



/** 
* @param string $libmot 
*/ 
public function setLibmot($libmot) 
{ 
    $this->libmot = $libmot; 
} 

/** 
* @return string 
*/ 
public function getLibmot() 
{ 
    return $this->libmot; 
} 


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

/** 
* Set titreFiche 
* 
* @param string $titreFiche 
* @return fiche 
*/ 
public function setTitreFiche($titreFiche) 
{ 
    $this->titreFiche = $titreFiche; 

    return $this; 
} 

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

/** 
* Set dateOuv 
* 
* @param \DateTime $dateOuv 
* @return fiche 
*/ 
public function setDateOuv($dateOuv) 
{ 
    $this->dateOuv = $dateOuv; 

    return $this; 
} 

/** 
* Get dateOuv 
* 
* @return \DateTime 
*/ 
public function getDateOuv() 
{ 
    return $this->dateOuv; 
} 


/** 
* Set observation 
* 
* @param string $observation 
* @return fiche 
*/ 
public function setObservation($observation) 
{ 
    $this->observation = $observation; 

    return $this; 
} 

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

/** 
* Set cause 
* 
* @param string $cause 
* @return fiche 
*/ 
public function setCause($cause) 
{ 
    $this->cause = $cause; 

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

/** 
* Set solution 
* 
* @param string $solution 
* @return fiche 
*/ 
public function setSolution($solution) 
{ 
    $this->solution = $solution; 

    return $this; 
} 

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

/** 
* Set comment 
* 
* @param string $comment 
* @return fiche 
*/ 
public function setComment($comment) 
{ 
    $this->comment = $comment; 

    return $this; 
} 

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

/** 
* Set confid 
* 
* @param string $confid 
* @return fiche 
*/ 
public function setConfid($confid) 
{ 
    $this->confid = $confid; 

    return $this; 
} 

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

/** 
* Set atteinteSecPerso 
* 
* @param string $atteinteSecPerso 
* @return fiche 
*/ 
public function setAtteinteSecPerso($atteinteSecPerso) 
{ 
    $this->atteinteSecPerso = $atteinteSecPerso; 

    return $this; 
} 

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

/** 
* Set perso 
* 
* @param string $perso 
* @return fiche 
*/ 
public function setPerso($perso) 
{ 
    $this->perso = $perso; 

    return $this; 
} 

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

/** 
* Set atteinteSecMat 
* 
* @param string $atteinteSecMat 
* @return fiche 
*/ 
public function setAtteinteSecMat($atteinteSecMat) 
{ 
    $this->atteinteSecMat = $atteinteSecMat; 

    return $this; 
} 

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

/** 
* Set mat 
* 
* @param string $mat 
* @return fiche 
*/ 
public function setMat($mat) 
{ 
    $this->mat = $mat; 

    return $this; 
} 

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

/** 
* Set planAct 
* 
* @param string $planAct 
* @return fiche 
*/ 
public function setPlanAct($planAct) 
{ 
    $this->planAct = $planAct; 

    return $this; 
} 

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

/** 
* Set cout 
* 
* @param string $cout 
* @return fiche 
*/ 
public function setCout($cout) 
{ 
    $this->cout = $cout; 

    return $this; 
} 

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

/** 
* Set delai 
* 
* @param string $delai 
* @return fiche 
*/ 
public function setDelai($delai) 
{ 
    $this->delai = $delai; 

    return $this; 
} 

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

/** 
* Set dateMEP 
* 
* @param \DateTime $dateMEP 
* @return fiche 
*/ 
public function setDateMEP($dateMEP) 
{ 
    $this->dateMEP = $dateMEP; 

    return $this; 
} 



/** 
* @param string $complexite 
*/ 
public function setComplexite($complexite) 
{ 
    $this->complexite = $complexite; 
} 

/** 
* @return string 
*/ 
public function getComplexite() 
{ 
    return $this->complexite; 
} 

/** 
* @param string $libService 
*/ 
public function setLibService($libService) 
{ 
    $this->libService = $libService; 
} 



/** 
* @return string 
*/ 
public function getLibService() 
{ 
    return $this->libService; 
} 

/** 
* Get dateMEP 
* 
* @return \DateTime 
*/ 
public function getDateMEP() 
{ 
    return $this->dateMEP; 
} 



/** 
* @param string $nom 
*/ 
public function setNom($nom) 
{ 
    $this->nom = $nom; 
} 

/** 
* @return string 
*/ 
public function getNom() 
{ 
    return $this->nom; 
} 


/** 
* @param string $libTypeAct 
*/ 
public function setLibTypeAct($libTypeAct) 
{ 
    $this->libTypeAct = $libTypeAct; 
} 

/** 
* @return string 
*/ 
public function getLibTypeAct() 
{ 
    return $this->libTypeAct; 
} 


/** 
* @param string $montant 
*/ 
public function setMontant($montant) 
{ 
    $this->montant = $montant; 
} 

/** 
* @return string 
*/ 
public function getMontant() 
{ 
    return $this->montant; 
} 


/** 
* @param string $valeur 
*/ 
public function setValeur($valeur) 
{ 
    $this->valeur = $valeur; 
} 

/** 
* @return string 
*/ 
public function getValeur() 
{ 
    return $this->valeur; 
} 


/** 
* @param string $libProcess 
*/ 
public function setLibProcess($libProcess) 
{ 
    $this->libProcess = $libProcess; 
} 

/** 
* @return string 
*/ 
public function getLibProcess() 
{ 
    return $this->libProcess; 
} 

/** 
* @ORM\OneToMany(targetEntity="rex\Bundle\Entity\document" , mappedBy="fiche", cascade={"all"}) 
*/ 
private $files; 

/** 
* @param mixed $files 
*/ 
public function __construct() 
{ 
    $this->files = new ArrayCollection(); 
} 


public function setFiles(ArrayCollection $files) 
{ 
    $this->files = $files; 
} 

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

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\systeme") 
* @ORM\JoinColumn 
*/ 
private $libSys; 

/** 
* @param string $libSys 
*/ 
public function setlibSys($libSys) 
{ 
    $this->libSys = $libSys; 
} 

/** 
* @return string 
*/ 
public function getlibSys() 
{ 
    return $this->libSys; 
} 
/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\UserBundle\Entity\User") 
* @ORM\JoinColumn (name="verificateur") 
*/ 
private $verificateur; 

/** 
* @param string $verificateur 
*/ 
public function setVerificateur($verificateur) 
{ 
    $this->verificateur = $verificateur; 
} 
/** 
* @return string 
*/ 
public function getVerificateur() 
{ 
    return $this->verificateur; 
} 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\equipement") 
* @ORM\JoinColumn 
*/ 
private $libEquip; 

/** 
* @param string $libEquip 
*/ 
public function setLibEquip($libEquip) 
{ 
    $this->libEquip = $libEquip; 
} 

/** 
* @return string 
*/ 
public function getLibEquip() 
{ 
    return $this->libEquip; 
} 

/** 
* @var string 
* @ORM\ManyToOne(targetEntity="rex\Bundle\Entity\phaseProjet") 
* @ORM\JoinColumn 
*/ 
private $libPhase; 

/** 
* @param string $libPhase 
*/ 
public function setLibPhase($libPhase) 
{ 
    $this->libPhase = $libPhase; 
} 

/** 
* @return string 
*/ 
public function getLibPhase() 
{ 
    return $this->libPhase; 
} 

public function getChemin(){ 

    $a = $this->getId(); 
    $finder = new Finder(); 

    if(is_dir(__DIR__ .'/../../../../web/uploads/'.$a)){ 
    $finder->files()->in(__DIR__ .'/../../../../web/uploads/'.$a); 
    // $finder->files()->size('< 50M'); 

      foreach ($finder as $file) { 
       if ($file->getRelativePathname()) 
       { 
       // affiche le chemin absolu 
       // print $file->getRealpath()."\n"; 

       $res = "<a href=\"http://localhost:8000/uploads/".$a."/".$file-  >getRelativePathname()."\" target=\"_blank\">".$file->getRelativePathname()."</a><BR>"; 
        print $res; 
        } 
       else {print"pas de fichier";}; 
        } 
    } 

    } 

     } 

这是config.yml我的教训博客

# Doctrine Configuration 
doctrine: 
dbal: 
    driver: "%database_driver%" 
    host:  "%database_host%" 
    port:  "%database_port%" 
    dbname: "%database_name%" 
    user:  "%database_user%" 
    password: "%database_password%" 
    charset: UTF8 

orm: 
    auto_generate_proxy_classes: "%kernel.debug%" 
    auto_mapping: true 
+0

我看不到任何异常 – 2014-10-28 10:58:06

+0

我有这个错误:“无法找到Fiche实体” – Simone 2014-10-28 12:04:34

+0

你有一个语法错误{%block body - %} theres a'-'太多 – 2014-10-28 14:05:24

如果我看到这个权利你的实体类文件应位于:

/path/to/your/project/src/rexBundle/Entity/fiche.php 

你有这个文件吗?

此外,请注意,您的命名约定非常不规范。 camelCase应仅用于方法和变量的命名。类/名称空间应该使用Capitalization命名约定。

+0

是的,我有一个Fiche实体 – Simone 2014-10-28 12:05:12

+0

文件中的类怎么样?它被命名为'fiche'?另外,你可以在你的问题中包含来自'config.yml'的'doctrine'块吗? – 2014-10-28 12:29:11

+0

这也将有助于,如果你会在你的问题中包含'fiche.php' ... – 2014-10-28 12:29:51

你可以简单地使用try和catch块......。像:

$entities = array(); 

try { 
$entities = $em->getRepository('rexBundle:fiche') 
    -> findBy(
     array('libEtatFi'=> 'brouillon'), 
     array('id' => 'ASC') 
    ); 
} catch(\Exception $e){ 

} 

return array(
    'entities' => $entities, 
); 
+0

我仍然有同样的错误 – Simone 2014-10-28 12:49:34

+0

实际上,我尝试添加'var_dump'但我什么都没有。 – Simone 2014-10-28 13:02:59

解决方案IST,当你在你的控制器的路线,像这样:

* @Route("/{id}", 

UND你想是这样的/平片,并且定义了路由/缩微胶片的方法是在/ {id}的方法下,比你有问题,因为找不到id“fiche”。愚蠢的,我知道。

因此,要完成这项工作,必须将方法放在/ {id}的方法上。 :-)