1
나는 두 클래스 인 Activity
과 Mandate
으로 작업하려고합니다. A Mandate
은 Activity
(어린이)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;
}
}
내 게시물에서 한 단어를 잊어 버린 것 같습니다. 나는 거기에 자리 표시자를 추가했습니다. 누락 된 단어로 바꾸거나 아무것도 잊어 버리지 않은 경우 아무것도 사용하지 마십시오. – greg0ire
감사합니다 greg0ire! – RaFF
지금 훨씬 더 의미가 있습니다 :) – greg0ire