1

我正在尝试使用 2 个类:ActivityMandate. AMandate是一个Activity(所以一个孩子)

我想通过单击带有授权 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));    
}

我的问题是我只能用他的父 Activity 搜索我的任务(因为我在任务中没有属性 ID)但是 setErase 方法仅用于任务,所以我有一个错误..

我必须通过在 Activity 中查找来搜索任务,但是我无法使用仅在 Mandate 类上创建的方法。

这是我的课堂活动:

   <?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;
    }

}
4

1 回答 1

0

谢谢您的帮助 !我终于找到了我的问题!

我不知道你必须穿上@MappedSuperclass超类而不是 Entity !

它的工作!

多么美好的一天!

于 2012-05-30T22:23:15.267 回答