probléme d'affiche image depuis autre entité

Par med001, il y a 10 ans


Salut, je crée deux entités matche et equipe et je fais la relation entre les 2 entités , j'écrit 2 attributs equipe1 et equipe2 dans l'entité match qui relié avec entité equipe
Maintenant j'ajoute match entre 2 equipes mais je trouve un probléme quand peut accés à l'image c'est à dire peut acceder à la nom de l'equipe mais je ne pas accéder à l'image .

Comment peut accéder à l'image c'est à dire quand il ajoute deux équipes et quand il affiche ce match entre 2 équipes comment accéder l'image de l'équipe
voici code de deux entités:

Matche.php

<?php namespace CrudBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\HttpFoundation\File\UploadedFile; use Doctrine\Common\Collections\ArrayCollection; /** * Matche * * @ORM\Table() * @ORM\Entity(repositoryClass="CrudBundle\Entity\MatcheRepository") */ class Matche { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="resultat_match", type="string", length=255) */ private $resultatMatch; /** * @var string * * @ORM\Column(name="nom_stade", type="string", length=255) */ private $nomStade; /** * @ORM\Column(type="string", length=255, nullable=true) */ public $path; /** * @Assert\File(maxSize="6000000") */ private $file; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Competition",mappedBy="matchs") */ private $competition; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Stade",mappedBy="matche") */ private $stade; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Matchequipe",mappedBy="match") */ private $matchequip; public function __construct() { $this->competition = new \Doctrine\Common\Collections\ArrayCollection(); $this->stade = new \Doctrine\Common\Collections\ArrayCollection(); $this->matchequip = new \Doctrine\Common\Collections\ArrayCollection(); } /** * @ORM\ManyToOne(targetEntity="Video",inversedBy="match") * @ORM\JoinColumn(name="id_video", referencedColumnName="id") */ private $video; /** * @ORM\ManyToOne(targetEntity="Photo",inversedBy="match") * @ORM\JoinColumn(name="id_photo", referencedColumnName="id") */ private $photo; /** * @ORM\ManyToOne(targetEntity="Article",inversedBy="match") * @ORM\JoinColumn(name="id_article", referencedColumnName="id") */ private $articles; /** * @ORM\ManyToOne(targetEntity="Actualite",inversedBy="match") * @ORM\JoinColumn(name="id_actualite", referencedColumnName="id") */ private $actualites; /** * @ORM\ManyToOne(targetEntity="Equipe",inversedBy="match1") * @ORM\JoinColumn(name="id_equipe1", referencedColumnName="id") */ private $equipe1; /** * @ORM\ManyToOne(targetEntity="Equipe",inversedBy="match2") * @ORM\JoinColumn(name="id_equipe2", referencedColumnName="id") */ private $equipe2; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set resultatMatch * * @param string $resultatMatch * @return Matche */ public function setResultatMatch($resultatMatch) { $this->resultatMatch = $resultatMatch; return $this; } /** * Get resultatMatch * * @return string */ public function getResultatMatch() { return $this->resultatMatch; } /** * Set nomStade * * @param string $nomStade * @return Matche */ public function setNomStade($nomStade) { $this->nomStade = $nomStade; return $this; } /** * Get nomStade * * @return string */ public function getNomStade() { return $this->nomStade; } public function getAbsolutePath() { return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; } public function getWebPath() { return null === $this->path ? null : $this->getUploadDir().'/'.$this->path; } protected function getUploadRootDir() { // the absolute directory path where uploaded // documents should be saved return __DIR__.'/../../../web/'.$this->getUploadDir(); } protected function getUploadDir() { // get rid of the __DIR__ so it doesn't screw up // when displaying uploaded doc/image in the view. return 'uploads/matche'; } /** * Sets file. * * @param UploadedFile $file */ public function setFile(UploadedFile $file = null) { $this->file = $file; } /** * Get file. * * @return UploadedFile */ public function getFile() { return $this->file; } public function upload() { // the file property can be empty if the field is not required if (null === $this->getFile()) { return; } // use the original file name here but you should // sanitize it at least to avoid any security issues // move takes the target directory and then the // target filename to move to $this->getFile()->move( $this->getUploadRootDir(), $this->getFile()->getClientOriginalName() ); // set the path property to the filename where you've saved the file $this->path = $this->getFile()->getClientOriginalName(); // clean up the file property as you won't need it anymore $this->file = null; } /** * Set path * * @param string $path * @return Matche */ public function setPath($path) { $this->path = $path; return $this; } /** * Get path * * @return string */ public function getPath() { return $this->path; } /** * Add competition * * @param \CrudBundle\Entity\Competition $competition * @return Matche */ public function addCompetition(\CrudBundle\Entity\Competition $competition) { $this->competition[] = $competition; return $this; } /** * Remove competition * * @param \CrudBundle\Entity\Competition $competition */ public function removeCompetition(\CrudBundle\Entity\Competition $competition) { $this->competition->removeElement($competition); } /** * Get competition * * @return \Doctrine\Common\Collections\Collection */ public function getCompetition() { return $this->competition; } /** * Add stade * * @param \CrudBundle\Entity\Stade $stade * @return Matche */ public function addStade(\CrudBundle\Entity\Stade $stade) { $this->stade[] = $stade; return $this; } /** * Remove stade * * @param \CrudBundle\Entity\Stade $stade */ public function removeStade(\CrudBundle\Entity\Stade $stade) { $this->stade->removeElement($stade); } /** * Get stade * * @return \Doctrine\Common\Collections\Collection */ public function getStade() { return $this->stade; } /** * Set video * * @param \CrudBundle\Entity\Video $video * @return Matche */ public function setVideo(\CrudBundle\Entity\Video $video = null) { $this->video = $video; return $this; } /** * Get video * * @return \CrudBundle\Entity\Video */ public function getVideo() { return $this->video; } /** * Set articles * * @param \CrudBundle\Entity\Article $articles * @return Matche */ public function setArticles(\CrudBundle\Entity\Article $articles = null) { $this->articles = $articles; return $this; } /** * Get articles * * @return \CrudBundle\Entity\Article */ public function getArticles() { return $this->articles; } /** * Set actualites * * @param \CrudBundle\Entity\Actualite $actualites * @return Matche */ public function setActualites(\CrudBundle\Entity\Actualite $actualites = null) { $this->actualites = $actualites; return $this; } /** * Get actualites * * @return \CrudBundle\Entity\Actualite */ public function getActualites() { return $this->actualites; } /** * Add matchequip * * @param \CrudBundle\Entity\Matchequipe $matchequip * @return Matche */ public function addMatchequip(\CrudBundle\Entity\Matchequipe $matchequip) { $this->matchequip[] = $matchequip; return $this; } /** * Remove matchequip * * @param \CrudBundle\Entity\Matchequipe $matchequip */ public function removeMatchequip(\CrudBundle\Entity\Matchequipe $matchequip) { $this->matchequip->removeElement($matchequip); } /** * Get matchequip * * @return \Doctrine\Common\Collections\Collection */ public function getMatchequip() { return $this->matchequip; } /** * Set photo * * @param \CrudBundle\Entity\Photo $photo * @return Matche */ public function setPhoto(\CrudBundle\Entity\Photo $photo = null) { $this->photo = $photo; return $this; } /** * Get photo * * @return \CrudBundle\Entity\Photo */ public function getPhoto() { return $this->photo; } /** * Set equipe1 * * @param \CrudBundle\Entity\Equipe $equipe1 * @return Matche */ public function setEquipe1(\CrudBundle\Entity\Equipe $equipe1 = null) { $this->equipe1 = $equipe1; return $this; } /** * Get equipe1 * * @return \CrudBundle\Entity\Equipe */ public function getEquipe1() { return $this->equipe1; } /** * Set equipe2 * * @param \CrudBundle\Entity\Equipe $equipe2 * @return Matche */ public function setEquipe2(\CrudBundle\Entity\Equipe $equipe2 = null) { $this->equipe2 = $equipe2; return $this; } /** * Get equipe2 * * @return \CrudBundle\Entity\Equipe */ public function getEquipe2() { return $this->equipe2; } }

code entité equipe :

<?php namespace CrudBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\HttpFoundation\File\UploadedFile; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * Equipe * * @ORM\Table() * @ORM\Entity(repositoryClass="CrudBundle\Entity\EquipeRepository") * @UniqueEntity("nomEquipe", message=" Une équipe existe déjà avec ce nom.") */ class Equipe { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * @ORM\Column(name="nom_equipe", type="string", length=255, unique=true) */ private $nomEquipe; /** * @ORM\Column(type="string", length=255, nullable=true) */ public $path; /** * @Assert\File(maxSize="6000000") */ private $file; /** * @var string * * @ORM\Column(name="contenu_equipe", type="string", length=255) */ private $contenuEquipe; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Joueur",mappedBy="equipes") */ private $joueurs; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Matchequipe",mappedBy="equipe") */ private $matchequip; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Matche",mappedBy="equipe1") */ private $match1; /** * @ORM\OneToMany(targetEntity="CrudBundle\Entity\Matche",mappedBy="equipe2") */ private $match2; public function __construct() { $this->joueurs = new \Doctrine\Common\Collections\ArrayCollection(); $this->matchequip = new \Doctrine\Common\Collections\ArrayCollection(); $this->match1 = new \Doctrine\Common\Collections\ArrayCollection(); $this->match2 = new \Doctrine\Common\Collections\ArrayCollection(); } /** * @ORM\ManyToOne(targetEntity="Article",inversedBy="equipe") * @ORM\JoinColumn(name="id_article", referencedColumnName="id") */ private $articles; /** * @ORM\ManyToOne(targetEntity="Actualite",inversedBy="equipe") * @ORM\JoinColumn(name="id_actualite", referencedColumnName="id") */ private $actualites; /** * @ORM\ManyToOne(targetEntity="Palmares",inversedBy="equipe") * @ORM\JoinColumn(name="id_palmares", referencedColumnName="id") */ private $palmares; /** * @ORM\ManyToOne(targetEntity="Staffmedical",inversedBy="equipe") * @ORM\JoinColumn(name="id_staffmedical", referencedColumnName="id") */ private $staffmedical; /** * @ORM\ManyToOne(targetEntity="Stafftechnique",inversedBy="equipe") * @ORM\JoinColumn(name="id_stafftechnique", referencedColumnName="id") */ private $stafftechnique; /** * @ORM\ManyToOne(targetEntity="Video",inversedBy="equipe") * @ORM\JoinColumn(name="id_video", referencedColumnName="id") */ private $video; /** * @ORM\ManyToOne(targetEntity="Photo",inversedBy="equipe") * @ORM\JoinColumn(name="id_photo", referencedColumnName="id") */ private $photo; /** * Get id * * @return integer */ public function getId() { return $this->id; } public function getAbsolutePath() { return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; } public function getWebPath() { return null === $this->path ? null : $this->getUploadDir().'/'.$this->path; } protected function getUploadRootDir() { // the absolute directory path where uploaded // documents should be saved return __DIR__.'/../../../web/'.$this->getUploadDir(); } protected function getUploadDir() { // get rid of the __DIR__ so it doesn't screw up // when displaying uploaded doc/image in the view. return 'uploads/equipe'; } /** * Sets file. * * @param UploadedFile $file */ public function setFile(UploadedFile $file = null) { $this->file = $file; } /** * Get file. * * @return UploadedFile */ public function getFile() { return $this->file; } public function upload() { // the file property can be empty if the field is not required if (null === $this->getFile()) { return; } // use the original file name here but you should // sanitize it at least to avoid any security issues // move takes the target directory and then the // target filename to move to $this->getFile()->move( $this->getUploadRootDir(), $this->getFile()->getClientOriginalName() ); // set the path property to the filename where you've saved the file $this->path = $this->getFile()->getClientOriginalName(); // clean up the file property as you won't need it anymore $this->file = null; } /** * Set path * * @param string $path * @return Article */ public function setPath($path) { $this->path = $path; return $this; } /** * Get path * * @return string */ public function getPath() { return $this->path; } /** * Set nomEquipe * * @param string $nomEquipe * @return Equipe */ public function setNomEquipe($nomEquipe) { $this->nomEquipe = $nomEquipe; return $this; } /** * Get nomEquipe * * @return string */ public function getNomEquipe() { return $this->nomEquipe; } /** * Set contenuEquipe * * @param string $contenuEquipe * @return Equipe */ public function setContenuEquipe($contenuEquipe) { $this->contenuEquipe = $contenuEquipe; return $this; } /** * Get contenuEquipe * * @return string */ public function getContenuEquipe() { return $this->contenuEquipe; } /** * Add joueurs * * @param \CrudBundle\Entity\Joueur $joueurs * @return Equipe */ public function addJoueur(\CrudBundle\Entity\Joueur $joueurs) { $this->joueurs[] = $joueurs; return $this; } /** * Remove joueurs * * @param \CrudBundle\Entity\Joueur $joueurs */ public function removeJoueur(\CrudBundle\Entity\Joueur $joueurs) { $this->joueurs->removeElement($joueurs); } /** * Get joueurs * * @return \Doctrine\Common\Collections\Collection */ public function getJoueurs() { return $this->joueurs; } /** * Set articles * * @param \CrudBundle\Entity\Article $articles * @return Equipe */ public function setArticles(\CrudBundle\Entity\Article $articles = null) { $this->articles = $articles; return $this; } /** * Get articles * * @return \CrudBundle\Entity\Article */ public function getArticles() { return $this->articles; } /** * Set actualites * * @param \CrudBundle\Entity\Actualite $actualites * @return Equipe */ public function setActualites(\CrudBundle\Entity\Actualite $actualites = null) { $this->actualites = $actualites; return $this; } /** * Get actualites * * @return \CrudBundle\Entity\Actualite */ public function getActualites() { return $this->actualites; } /** * Set palmares * * @param \CrudBundle\Entity\Palmares $palmares * @return Equipe */ public function setPalmares(\CrudBundle\Entity\Palmares $palmares = null) { $this->palmares = $palmares; return $this; } /** * Get palmares * * @return \CrudBundle\Entity\Palmares */ public function getPalmares() { return $this->palmares; } /** * Set staffmedical * * @param \CrudBundle\Entity\Staffmedical $staffmedical * @return Equipe */ public function setStaffmedical(\CrudBundle\Entity\Staffmedical $staffmedical = null) { $this->staffmedical = $staffmedical; return $this; } /** * Get staffmedical * * @return \CrudBundle\Entity\Staffmedical */ public function getStaffmedical() { return $this->staffmedical; } /** * Set stafftechnique * * @param \CrudBundle\Entity\Stafftechnique $stafftechnique * @return Equipe */ public function setStafftechnique(\CrudBundle\Entity\Stafftechnique $stafftechnique = null) { $this->stafftechnique = $stafftechnique; return $this; } /** * Get stafftechnique * * @return \CrudBundle\Entity\Stafftechnique */ public function getStafftechnique() { return $this->stafftechnique; } /** * Set video * * @param \CrudBundle\Entity\Video $video * @return Equipe */ public function setVideo(\CrudBundle\Entity\Video $video = null) { $this->video = $video; return $this; } /** * Get video * * @return \CrudBundle\Entity\Video */ public function getVideo() { return $this->video; } /** * Add matchequip * * @param \CrudBundle\Entity\Matchequipe $matchequip * @return Equipe */ public function addMatchequip(\CrudBundle\Entity\Matchequipe $matchequip) { $this->matchequip[] = $matchequip; return $this; } /** * Remove matchequip * * @param \CrudBundle\Entity\Matchequipe $matchequip */ public function removeMatchequip(\CrudBundle\Entity\Matchequipe $matchequip) { $this->matchequip->removeElement($matchequip); } /** * Get matchequip * * @return \Doctrine\Common\Collections\Collection */ public function getMatchequip() { return $this->matchequip; } /** * Set photo * * @param \CrudBundle\Entity\Photo $photo * @return Equipe */ public function setPhoto(\CrudBundle\Entity\Photo $photo = null) { $this->photo = $photo; return $this; } /** * Get photo * * @return \CrudBundle\Entity\Photo */ public function getPhoto() { return $this->photo; } /** * Add match1 * * @param \CrudBundle\Entity\Matche $match1 * @return Equipe */ public function addMatch1(\CrudBundle\Entity\Matche $match1) { $this->match1[] = $match1; return $this; } /** * Remove match1 * * @param \CrudBundle\Entity\Matche $match1 */ public function removeMatch1(\CrudBundle\Entity\Matche $match1) { $this->match1->removeElement($match1); } /** * Get match1 * * @return \Doctrine\Common\Collections\Collection */ public function getMatch1() { return $this->match1; } /** * Add match2 * * @param \CrudBundle\Entity\Matche $match2 * @return Equipe */ public function addMatch2(\CrudBundle\Entity\Matche $match2) { $this->match2[] = $match2; return $this; } /** * Remove match2 * * @param \CrudBundle\Entity\Matche $match2 */ public function removeMatch2(\CrudBundle\Entity\Matche $match2) { $this->match2->removeElement($match2); } /** * Get match2 * * @return \Doctrine\Common\Collections\Collection */ public function getMatch2() { return $this->match2; } }

coed match.twig.html:

<h1>Liste des Matchs</h1> <table> <thead> <th>nom stade </th> <th>resultat </th> <th>Equipe 1 </th> <th>Equipe 2 </th> <th>image Match </th> </thead> <tbody> {% for matc in matche %} <tr><td> {{ matc.nomStade }}</td> <td>{{ matc.resultatMatch }}</td> <td>{{ matc.getEquipe1().getNomEquipe() }}</td> <td>{{ matc.getEquipe2().getNomEquipe() }}</td> <td><img style="width:400px; height:400px;" src="{{ asset('uploads/equipe/'~matc.path) }}" </tr> {% endfor %} </tbody> </table>

Aucune réponse