Symfony2
anibar.ysf
Messages postés
9
Date d'inscription
Statut
Membre
Dernière intervention
-
kangourouxxx Messages postés 71 Date d'inscription Statut Membre Dernière intervention -
kangourouxxx Messages postés 71 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
je suis débutant en framework symfony2 et je n'arrive pas a afficher ma page view !!!
il m'affiche

voilà le code de mon controlleur Advert
<?php
// src/OC/PlatformBundle/Controller/AdvertController.php
namespace OC\PlatformBundle\Controller;
use OC\PlatformBundle\Entity\AdvertRepository;
use OC\PlatformBundle\Entity\Application;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class AdvertController extends Controller
{
public function viewAction($id)
{
$em = $this->getDoctrine()->getManager();
// On récupère l'annonce $id
$advert = $em
->getRepository('OCPlatformBundle:Advert')
->find($id)
;
if (null === $advert) {
throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
}
// On récupère la liste des candidatures de cette annonce
$listApplications = $em
->getRepository('OCPlatformBundle:Application')
->findBy(array('advert' => $advert))
;
return $this->render('OCPlatformBundle:Advert:view.html.twig', array(
'advert' => $advert,
'listApplications' => $listApplications
));
}
}
et voilà le code de mon entité Advert
<?php
// src/OC/PlatformBundle/Entity/Advert.php
namespace OC\PlatformBundle\Entity;
// On définit le namespace des annotations utilisées par Doctrine2
// En effet, il existe d'autres annotations, on le verra par la suite,
// qui utiliseront un autre namespace
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="OC\PlatformBundle\Entity\AdvertRepository")
*/
class Advert
{
/**
* @ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist"})
*/
private $image;
// Vos autres attributs...
public function setImage(Image $image = null)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="date", type="date")
*/
protected $date;
/**
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* @ORM\Column(name="author", type="string", length=255)
*/
protected $author;
/**
* @ORM\Column(name="content", type="text")
*/
protected $content;
/**
* @ORM\Column(name="published", type="boolean")
*/
private $published = true;
public function __construct()
{
// Par défaut, la date de l'annonce est la date d'aujourd'hui
$this->date = new \Datetime();
}
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setDate($date)
{
$this->date = $date;
}
public function getDate()
{
return $this->date;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getTitle()
{
return $this->title;
}
public function setAuthor($author)
{
$this->author = $author;
}
public function getAuthor()
{
return $this->author;
}
public function setContent($content)
{
$this->content = $content;
}
public function getContent()
{
return $this->content;
}
public function setPublished($published)
{
$this->published = $published;
}
public function getPublished()
{
return $this->published;
}
public function getPrixTotal()
{
$prix = 0;
foreach($this->getListeProduits() as $produit)
{
$prix += $produit->getPrix();
}
return $prix;
}
}
je suis débutant en framework symfony2 et je n'arrive pas a afficher ma page view !!!
il m'affiche

voilà le code de mon controlleur Advert
<?php
// src/OC/PlatformBundle/Controller/AdvertController.php
namespace OC\PlatformBundle\Controller;
use OC\PlatformBundle\Entity\AdvertRepository;
use OC\PlatformBundle\Entity\Application;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class AdvertController extends Controller
{
public function viewAction($id)
{
$em = $this->getDoctrine()->getManager();
// On récupère l'annonce $id
$advert = $em
->getRepository('OCPlatformBundle:Advert')
->find($id)
;
if (null === $advert) {
throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
}
// On récupère la liste des candidatures de cette annonce
$listApplications = $em
->getRepository('OCPlatformBundle:Application')
->findBy(array('advert' => $advert))
;
return $this->render('OCPlatformBundle:Advert:view.html.twig', array(
'advert' => $advert,
'listApplications' => $listApplications
));
}
}
et voilà le code de mon entité Advert
<?php
// src/OC/PlatformBundle/Entity/Advert.php
namespace OC\PlatformBundle\Entity;
// On définit le namespace des annotations utilisées par Doctrine2
// En effet, il existe d'autres annotations, on le verra par la suite,
// qui utiliseront un autre namespace
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="OC\PlatformBundle\Entity\AdvertRepository")
*/
class Advert
{
/**
* @ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist"})
*/
private $image;
// Vos autres attributs...
public function setImage(Image $image = null)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="date", type="date")
*/
protected $date;
/**
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* @ORM\Column(name="author", type="string", length=255)
*/
protected $author;
/**
* @ORM\Column(name="content", type="text")
*/
protected $content;
/**
* @ORM\Column(name="published", type="boolean")
*/
private $published = true;
public function __construct()
{
// Par défaut, la date de l'annonce est la date d'aujourd'hui
$this->date = new \Datetime();
}
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setDate($date)
{
$this->date = $date;
}
public function getDate()
{
return $this->date;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getTitle()
{
return $this->title;
}
public function setAuthor($author)
{
$this->author = $author;
}
public function getAuthor()
{
return $this->author;
}
public function setContent($content)
{
$this->content = $content;
}
public function getContent()
{
return $this->content;
}
public function setPublished($published)
{
$this->published = $published;
}
public function getPublished()
{
return $this->published;
}
public function getPrixTotal()
{
$prix = 0;
foreach($this->getListeProduits() as $produit)
{
$prix += $produit->getPrix();
}
return $prix;
}
}