2012-05-30 135 views
1

我想與2個班級合作:ActivityMandate。 A MandateActivity(所以一個孩子)Symfony 2:兒童班

我想通過點擊與任務的ID的鏈接消除任務。

因此,這裏是我的行動:

public function eraseAction($id = null) 
{ 
    $em = $this->container->get('doctrine')->getEntityManager(); 

    if (isset($id)) 
    { 
     // existing user edition : let's load its data 
     $mandate = $em->find('MyAppToolsBundle:Activity', $id); 

     if (!$mandate) 
     { 
      $message = 'Error while deleting the record'; 
     } 
     else 
     { 
     $mandate->setErase(true); 
     } 
    } 
    else 
    { 
     $message = 'erreur'; 
    } 

    return $this->container->get('templating')->renderResponse('MyAppToolsBundle:Admin:mandate.html.twig',array(
    'message' => $message));  
} 

我的問題是,我只能搜索我的任務與他的父活動(因爲我沒有在任務屬性ID),但該方法setErase僅用於一個任務,所以我有一個錯誤..

我必須通過查找在活動中搜索任務,但是我不能使用我只在任務類創建的方法。

這裏是我的課外活動:

<?php 
    namespace MyApp\ToolsBundle\Entity; 
    use Doctrine\ORM\Mapping as ORM; 
    use Symfony\Component\Validator\Constraints as Assert; 

    /** 
    * @ORM\Entity 
    */ 
    class Activity 
    { 
     /** 
     * @ORM\GeneratedValue 
     * @ORM\Id 
     * @ORM\Column(type="integer") 
     */ 
     private $id; 

     /** 
     * @ORM\OneToMany(targetEntity="MyApp\ToolsBundle\Entity\Hour", mappedBy="activity") 
     */ 
     protected $hour; 

     /** 
     * @ORM\Column(type="string",length="255") 
     * @Assert\NotBlank() 
     * @Assert\MinLength(2) 
     */  
     private $name; 

     /** 
     * @ORM\Column(type="string",length="20") 
     * @Assert\NotBlank() 
     */  
     private $color; 

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

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

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

     /** 
     * Set color 
     * 
     * @param string $color 
     */ 
     public function setColor($color) 
     { 
      $this->color = $color; 
     } 

     /** 
     * Get color 
     * 
     * @return string 
     */ 
     public function getColor() 
     { 
      return $this->color; 
     } 
     public function __construct() 
     { 
      $this->hours = new \Doctrine\Common\Collections\ArrayCollection(); 
     } 

     /** 
     * Add hours 
     * 
     * @param Furter\OutilGestionBundle\Entity\Hour $hours 
     */ 
     public function addHour(\MyApp\ToolsBundle\Entity\Hour $hours) 
     { 
      $this->hours[] = $hours; 
     } 

     /** 
     * Get hours 
     * 
     * @return Doctrine\Common\Collections\Collection 
     */ 
     public function getHours() 
     { 
      return $this->hours; 
     } 

     /** 
     * Get hour 
     * 
     * @return Doctrine\Common\Collections\Collection 
     */ 
     public function getHour() 
     { 
      return $this->hour; 
     } 
    } 

而我的任務等級:

<?php 
namespace MyApp\ToolsBundle\Entity; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity 
*/ 
class Mandate extends Activity 
{ 

    /** 
    * @ORM\Column(type="date") 
    */ 
    private $startdate; 

    /** 
    * @ORM\Column(type="date") 
    */ 
    private $enddate; 

    /** 
    * @ORM\Column(type="boolean") 
    */ 
    private $erase = 0; 



    /** 
    * @ORM\OneToMany(targetEntity="MyApp\ToolsBundle\Entity\Hour", mappedBy="activity") 
    */ 
    protected $hour; 

    /** 
    * @ORM\OneToOne(targetEntity="MyApp\ToolsBundle\Entity\Client") 
    */ 
    private $client; 


    /** 
    * Set startdate 
    * 
    * @param date $startdate 
    */ 
    public function setStartdate($startdate) 
    { 
     $this->startdate = $startdate; 
    } 

    /** 
    * Get startdate 
    * 
    * @return date 
    */ 
    public function getStartdate() 
    { 
     return $this->startdate; 
    } 

    /** 
    * Set enddate 
    * 
    * @param date $enddate 
    */ 
    public function setEnddate($enddate) 
    { 
     $this->enddate = $enddate; 
    } 

    /** 
    * Get enddate 
    * 
    * @return date 
    */ 
    public function getEnddate() 
    { 
     return $this->enddate; 
    } 
    /** 
    * @var MyApp\ToolsBundle\Entity\Hour 
    */ 
    private $hours; 

    public function __construct() 
    { 
     $this->hours = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 

    /** 
    * Add hours 
    * 
    * @param MyApp\ToolsBundle\Entity\Hour $hours 
    */ 
    public function addHour(\MyApp\ToolsBundle\Entity\Hour $hours) 
    { 
     $this->hours[] = $hours; 
    } 

    /** 
    * Get hours 
    * 
    * @return Doctrine\Common\Collections\Collection 
    */ 
    public function getHours() 
    { 
     return $this->hours; 
    } 

    /** 
    * Get hour 
    * 
    * @return Doctrine\Common\Collections\Collection 
    */ 
    public function getHour() 
    { 
     return $this->hour; 
    } 

    /** 
    * Set client 
    * 
    * @param MyApp\ToolsBundle\Entity\Client $client 
    */ 
    public function setClient(\MyApp\ToolsBundle\Entity\Client $client) 
    { 
     $this->client = $client; 
    } 

    /** 
    * Get client 
    * 
    * @return MyApp\ToolsBundle\Entity\Client 
    */ 
    public function getClient() 
    { 
     return $this->client; 
    } 

    /** 
    * Set erase 
    * 
    * @param boolean $erase 
    */ 
    public function setErase($erase) 
    { 
     $this->erase = $erase; 
    } 

    /** 
    * Get erase 
    * 
    * @return boolean 
    */ 
    public function getErase() 
    { 
     return $this->erase; 
    } 

} 
+0

我想你忘了在你的文章中的一個詞。我在其中添加了一個佔位符。用丟失的詞替換它,或者如果你沒有遺忘任何東西,就用什麼都不用。 – greg0ire

+0

謝謝greg0ire! – RaFF

+0

現在更有意義:) – greg0ire

回答

0

謝謝您的幫助!我最終發現我的問題!

我不知道你必須把@MappedSuperclass放在超類而不是實體!

它的工作!

真是一天!