2017-10-16 10 views
0

En vedette pour cela pendant plusieurs heures maintenant, peut-être que j'ai manqué quelque chose d'évident.Symfony3 - Les entités ne fonctionnent pas avec les relations (base de données avec les index et les contraintes)

Avoir cette structure de base de données (avec index et contraintes)

CREATE TABLE `exploit` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `edb_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL, 
    `date` datetime not null, 
    `author` bigint(20) not null , 
    `name` varchar(255) not null, 
    `category` bigint(20) not null, 
    `version` varchar(255) not null, 
    `type` bigint(20) not null, 
    `content` longtext COLLATE utf8_unicode_ci NOT NULL, 
    `dork` varchar(255) null, 
    `software_link` varchar(255) null, 
    `tested_on` varchar(255) null, 
    PRIMARY KEY (`id`), 
    KEY `exploit_category_idx` (`category`), 
    KEY `exploit_type_idx` (`type`), 
    KEY `exploit_author_idx` (`author`) 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

CREATE TABLE `category` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `category_name_id_idx` (`id`), 
    CONSTRAINT `category_name_id` FOREIGN KEY (`id`) REFERENCES `exploit` (`category`) ON DELETE CASCADE 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

CREATE TABLE `type` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `type_name_id_idx` (`id`), 
    CONSTRAINT `type_name_id` FOREIGN KEY (`id`) REFERENCES `exploit` (`type`) ON DELETE CASCADE 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

CREATE TABLE `author` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `author_name_id_idx` (`id`), 
    CONSTRAINT `author_name_id` FOREIGN KEY (`id`) REFERENCES `exploit` (`author`) ON DELETE CASCADE 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

créé ces entités:

:::::::::::::: 
Author.php 
:::::::::::::: 
<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* Author 
* 
* @ORM\Table(name="author", indexes={@ORM\Index(name="author_name_id_idx", columns={"id"})}) 
* @ORM\Entity 
*/ 
class Author 
{ 

    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="NONE") 
    */ 
    private $id; 

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


/** 
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Exploit", mappedBy="author", cascade={"persist", "remove"}) 
* @ORM\JoinColumn(name="exploits", referencedColumnName="id") 
*/ 
private $exploits; 

/** 
* Author constructor. 
*/ 
public function __construct() 
{ 
    $this->exploits = new ArrayCollection(); 
} 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Author 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

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

    public function __toString() 
    { 
     return $this->name; 
    } 


/** 
* @param Exploits $exploit 
* 
* @return Author 
*/ 
public function addExploit($exploit) 
{ 
     $this->exploits->add($exploit); 

    return $this; 
} 

/** 
* @param Collection $exploits 
* 
* @return Author 
*/ 
public function setExploits(Collection $exploits) 
{ 
    $this->exploits->clear(); 

    foreach ($exploits as $exploit) { 
     $exploit->add($this); 
    } 

    $this->exploits = $exploits; 

    return $this; 
} 
} 
:::::::::::::: 
Category.php 
:::::::::::::: 
<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* Category 
* 
* @ORM\Table(name="category", indexes={@ORM\Index(name="category_name_id_idx", columns={"id"})}) 
* @ORM\Entity 
*/ 
class Category 
{ 

    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="NONE") 
    */ 
    private $id; 

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


/** 
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Exploit", mappedBy="category", cascade={"persist", "remove"}) 
* @ORM\JoinColumn(name="exploits", referencedColumnName="id") 
*/ 
private $exploits; 

/** 
* Author constructor. 
*/ 
public function __construct() 
{ 
    $this->exploits = new ArrayCollection(); 
} 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Author 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

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

    public function __toString() 
    { 
     return $this->name; 
    } 


/** 
* @param Exploits $exploit 
* 
* @return Author 
*/ 
public function addExploit($exploit) 
{ 
     $this->exploits->add($exploit); 

    return $this; 
} 

/** 
* @param Collection $exploits 
* 
* @return Author 
*/ 
public function setExploits(Collection $exploits) 
{ 
    $this->exploits->clear(); 

    foreach ($exploits as $exploit) { 
     $exploit->add($this); 
    } 

    $this->exploits = $exploits; 

    return $this; 
} 
} 
:::::::::::::: 
Exploit.php 
:::::::::::::: 
<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Author; 
use AppBundle\Entity\Type; 
use AppBundle\Entity\Category; 

/** 
* Exploit 
* 
* @ORM\Table(name="exploit", indexes={@ORM\Index(name=exploit_category_idx", columns={"category"}), @ORM\Index(name="exploit_type_idx", columns={"type"}), @ORM\Index(name="exploit_author_idx", columns={" 
author"})}) 
*/ 
class Exploit 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="bigint", nullable=false) 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="IDENTITY") 
    */ 
    private $id; 

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

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

    /** 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Author", inversedBy="exploits") 
    * @ORM\JoinColumn(name="author", referencedColumnName="id") 
    */ 
    private $author; 

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

    /** 
    * @var integer 
    * 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="exploits") 
    * @ORM\JoinColumn(name="category", referencedColumnName="id") 
    */ 
    private $category; 

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

    /** 
    * @var integer 
    * 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Type", inversedBy="exploits") 
    * @ORM\JoinColumn(name="type", referencedColumnName="id") 
    */ 
    private $type; 

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

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

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

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



    /** 
    * Set edbId 
    * 
    * @param integer $edbId 
    * 
    * @return Exploit 
    */ 
    public function setEdbId($edbId) 
    { 
     $this->edbId = $edbId; 

     return $this; 
    } 

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

    /** 
    * Set date 
    * 
    * @param \DateTime $date 
    * 
    * @return Exploit 
    */ 
    public function setDate($date) 
    { 
     $this->date = $date; 

     return $this; 
    } 

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

    /** 
    * Set author 
    * 
    * @param integer $author 
    * 
    * @return Exploit 
    */ 
    public function setAuthor($author) 
    { 
     $this->author = $author; 

     return $this; 
    } 

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

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Exploit 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

    /** 
    * Set category 
    * 
    * @param integer $category 
    * 
    * @return Exploit 
    */ 
    public function setCategory($category) 
    { 
     $this->category = $category; 

     return $this; 
    } 

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

    /** 
    * Set version 
    * 
    * @param string $version 
    * 
    * @return Exploit 
    */ 
    public function setVersion($version) 
    { 
     $this->version = $version; 

     return $this; 
    } 

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

    /** 
    * Set type 
    * 
    * @param integer $type 
    * 
    * @return Exploit 
    */ 
    public function setType($type) 
    { 
     $this->type = $type; 

     return $this; 
    } 

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

    /** 
    * Set content 
    * 
    * @param string $content 
    * 
    * @return Exploit 
    */ 
    public function setContent($content) 
    { 
     $this->content = $content; 

     return $this; 
    } 

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

    /** 
    * Set dork 
    * 
    * @param string $dork 
    * 
    * @return Exploit 
    */ 
    public function setDork($dork) 
    { 
     $this->dork = $dork; 

     return $this; 
    } 

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

    /** 
    * Set softwareLink 
    * 
    * @param string $softwareLink 
    * 
    * @return Exploit 
    */ 
    public function setSoftwareLink($softwareLink) 
    { 
     $this->softwareLink = $softwareLink; 

     return $this; 
    } 

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

    /** 
    * Set testedOn 
    * 
    * @param string $testedOn 
    * 
    * @return Exploit 
    */ 
    public function setTestedOn($testedOn) 
    { 
     $this->testedOn = $testedOn; 

     return $this; 
    } 

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

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 
} 
:::::::::::::: 
Type.php 
:::::::::::::: 
<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* Type 
* 
* @ORM\Table(name="type", indexes={@ORM\Index(name="type_name_id_idx", columns={"id"})}) 
* @ORM\Entity 
*/ 
class Type 
{ 

    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="NONE") 
    */ 
    private $id; 

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


/** 
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Exploit", mappedBy="type", cascade={"persist", "remove"}) 
* @ORM\JoinColumn(name="exploits", referencedColumnName="id") 
*/ 
private $exploits; 

/** 
* Type constructor. 
*/ 
public function __construct() 
{ 
    $this->exploits = new ArrayCollection(); 
} 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Type 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

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

    public function __toString() 
    { 
     return $this->name; 
    } 


/** 
* @param Exploits $exploit 
* 
* @return Type 
*/ 
public function addExploit($exploit) 
{ 
     $this->exploits->add($exploit); 

    return $this; 
} 

/** 
* @param Collection $exploits 
* 
* @return Type 
*/ 
public function setExploits(Collection $exploits) 
{ 
    $this->exploits->clear(); 

    foreach ($exploits as $exploit) { 
     $exploit->add($this); 
    } 

    $this->exploits = $exploits; 

    return $this; 
} 

} 

mais en quelque sorte quand je fais une requête que je reçois, comme:

$exploits = $this->getDoctrine() 
      ->getRepository('AppBundle:Exploit') 
      ->findAll(); 

et à vue

<th scope="row"> {{ exploit.id }} </th> 
     <td> {{ exploit.name }} </td> 
     <td> {{ exploit.author.name }} </td> 
     <td> {{ exploit.type.name }} </td> 
     <td> {{ exploit.category.name }} </td> 
     <td>{{ exploit.date|date('F j, Y, g:i a') }}</td> 

Je reçois cette erreur:

Impossible to access an attribute ("name") on a integer variable ("1"). 

Toute bonne âme peut regarder cette question et essayer de le reproduire?

MySQL Dump pour recréer les tables avec le contenu est ici:

https://0bin.net/paste/2tV3MEw4A2tdAVsR#R3rBNW4seWkK9HtlJFwbsA6+RmhhWPilm40L8QfeiTp

Merci!

Répondre

1

Il dit juste là, vous essayez d'accéder à l'attribut name de quelque chose, mais que quelque chose n'est pas un objet. C'est un 1.

Vous accédez .name plusieurs fois si peu sûr que l'un de ces il est sans plus d'informations et un numéro de ligne

<th scope="row"> {{ exploit.id }} </th> 
    <td> {{ exploit.name }} </td> 
    <td> {{ exploit.author.name }} </td> 
    <td> {{ exploit.type.name }} </td> 
    <td> {{ exploit.category.name }} </td> 
    <td>{{ exploit.date|date('F j, Y, g:i a') }}</td> 
</th> 

Mais si nous supposons son Author alors son clair que la méthode getAuthor() retourne un bigint.

Comment avez-vous obtenu ce code d'entité et le code de la base de données? Parce qu'ils ne semblent pas corrects, ils obtiennent et définissent des entiers, plutôt que des objets.

MISE À JOUR

Générez entités

php bin/console doctrine:generate:entities AppBundle 

Voir SQL en utilisant

php bin/console doctrine:schema:update --dump-sql 

Execute SQL en utilisant

php bin/console doctrine:schema:update --force 
+0

Merci !!! Vous avez le point là. J'ai créé DB à la main. Au début, j'ai créé des entités à partir de la base de données (2 commandes Symfony) et l'ai réglé après avoir lu les tutoriels et les réponses SO. Comment puis-je générer correctement des entités en fonction de mon schéma de base de données ou comment/comment dois-je ajuster pour qu'il fonctionne avec mes entités actuelles? GRAND MERCI! –

+0

:/Toujours pareil ... Impossible d'accéder à un attribut ("nom") sur une variable entière ("1") –

+0

Je remplis DB avec d'autres scripts Python ... cela pourrait-il être le problème? –

0

obtenu ce travail avec ces entités:

:::::::::::::: 
Author.php 
:::::::::::::: 
<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* User 
* 
* @ORM\Table(name="author") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") 
*/ 
class Author 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="a_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $a_id; 

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

    /** 
    * @ORM\OneToMany(targetEntity="Exploit", mappedBy="author") 
    */ 
    protected $exploits; 

    public function __construct() 
    { 
     $this->exploits = new ArrayCollection(); 
    } 

    public function addExploit(\AppBundle\Entity\Exploit $exploit) 
    { 
     $this->report[] = $exploit; 
    } 

    public function getExploits() 
    { 
     return $this->exploits; 
    } 
    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Type 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

} 

:::::::::::::: 
Category.php 
:::::::::::::: 
<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* Category 
* 
* @ORM\Table(name="category") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository") 
*/ 
class Category 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="c_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $c_id; 

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

/** 
    * @ORM\OneToMany(targetEntity="Exploit", mappedBy="category") 
    */ 
    protected $exploits; 

    public function __construct() 
    { 
     $this->exploits = new ArrayCollection(); 
    } 

    public function addExploit(\AppBundle\Entity\Exploit $exploit) 
    { 
     $this->report[] = $exploit; 
    } 

    public function getExploits() 
    { 
     return $this->exploits; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Type 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

} 

:::::::::::::: 
Exploit.php 
:::::::::::::: 
<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Author; 

/** 
* Exploit 
* 
* @ORM\Table(name="exploit") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\ReportRepository") 
*/ 
class Exploit 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="e_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $e_id; 

    /** 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Author", inversedBy="exploi 
ts") 
    * @ORM\JoinColumn(name="author_id", referencedColumnName="a_id") 
    */ 
    protected $author; 

    public function setAuthor(\AppBundle\Entity\Author $author) 
    { 
     $this->author = $author; 
    } 

    public function getAuthor() 
    { 
     return $this->author; 
    } 

     /** 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="expl 
oits") 
    * @ORM\JoinColumn(name="category_id", referencedColumnName="c_id") 
    */ 
    protected $category; 

    public function setCategory(\AppBundle\Entity\Category $category) 
    { 
     $this->category = $category; 
    } 

    public function getCategory() 
    { 
     return $this->category; 
    } 

     /** 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Type", inversedBy="exploits 
") 
    * @ORM\JoinColumn(name="type_id", referencedColumnName="t_id") 
    */ 
    protected $type; 

    public function setType(\AppBundle\Entity\Type $type) 
    { 
     $this->type = $type; 
    } 

    public function getType() 
    { 
     return $this->type; 
    } 

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

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


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

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

    /** 
    * @var string 
    * 
    * @ORM\Column(name="software_link", type="string", length=255, nullable=tru 
e) 
    */ 
    private $softwareLink; 

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

    /** 
    * Set edbId 
    * 
    * @param integer $edbId 
    * 
    * @return Exploit 
    */ 
    public function setEdbId($edbId) 
    { 
     $this->edbId = $edbId; 

     return $this; 
    } 

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

    /** 
    * Set date 
    * 
    * @param \DateTime $date 
    * 
    * @return Exploit 
    */ 
    public function setDate($date) 
    { 
     $this->date = $date; 

     return $this; 
    } 

    /** 
    * Get date 
    * 
    * @return \DateTime 
    */ 
    public function getDate() 
    { 
     return $this->date; 
    } 
/** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Exploit 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 
/** 
    * Set version 
    * 
    * @param string $version 
    * 
    * @return Exploit 
    */ 
    public function setVersion($version) 
    { 
     $this->version = $version; 

     return $this; 
    } 

    /** 
    * Get version 
    * 
    * @return string 
    */ 
    public function getVersion() 
    { 
     return $this->version; 
    } 
/** 
    * Set content 
    * 
    * @param string $content 
    * 
    * @return Exploit 
    */ 
    public function setContent($content) 
    { 
     $this->content = $content; 

     return $this; 
    } 

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

    /** 
    * Set dork 
    * 
    * @param string $dork 
    * 
    * @return Exploit 
    */ 
    public function setDork($dork) 
    { 
     $this->dork = $dork; 

     return $this; 
    } 

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

    /** 
    * Set softwareLink 
    * 
    * @param string $softwareLink 
    * 
    * @return Exploit 
    */ 
    public function setSoftwareLink($softwareLink) 
    { 
     $this->softwareLink = $softwareLink; 

     return $this; 
    } 

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

    /** 
    * Set testedOn 
    * 
    * @param string $testedOn 
    * 
    * @return Exploit 
    */ 
    public function setTestedOn($testedOn) 
    { 
     $this->testedOn = $testedOn; 

     return $this; 
    } 

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

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




} 

:::::::::::::: 
Type.php 
:::::::::::::: 
<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use AppBundle\Entity\Exploit; 

/** 
* Type 
* 
* @ORM\Table(name="type") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\TypeRepository") 
*/ 
class Type 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="t_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $t_id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="name", type="string", length=255, nullable=false) 
    */ 
    private $name; 
/** 
    * @ORM\OneToMany(targetEntity="Exploit", mappedBy="type") 
    */ 
    protected $exploits; 

    public function __construct() 
    { 
     $this->exploits = new ArrayCollection(); 
    } 

    public function addExploit(\AppBundle\Entity\Exploit $exploit) 
    { 
     $this->report[] = $exploit; 
    } 

    public function getExploits() 
    { 
     return $this->exploits; 
    } 


    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Type 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

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

} 

Ce point de vue:

{% for exploit in exploits %} 
      <tr> 
       <th scope="row">{{ exploit.e_id }}</th> 
       <td>{{ exploit.name }}</td> 
       <td> {{ exploit.author.name }} </td> 
       <td> {{ exploit.category.name }} </td> 
       <td> {{ exploit.type.name }} </td> 

       <td> 
        <a href="/details/{{ exploit.e_id }}" class="btn btn-success">View</a> 
        <a href="/edit/{{ exploit.e_id }}" class="btn btn-default">Edit</a> 
        <a href="/delete/{{ exploit.e_id }}" class="btn btn-danger">Delete</a> 
       </td> 
      </tr> 
      {% endfor %} 

Et contrôleur:

$exploits = $this->getDoctrine() 
    ->getRepository('AppBundle:Exploit') 
    ->findAll(); 

return $this->render('exploit/index.html.twig', array(
    'exploits' => $exploits 
));