Symfony2를 사용하여 응용 프로그램을 만들려고하고 있습니다. 알아낼 수없는 것에 대비해 왔습니다. Company와 Entity라는 엔티티가 Many to Many 관계 (일대 다 많아야하지만 이것은 Symfony/Doctrine이 처리하는 방식이라고 생각합니다)라고합니다. 즉 각 회사는 하나 이상의 주소를 가질 수 있습니다. Gedmo의 Doctrine Extensions를 설정하고 두 엔티티에서 timestampable을 사용하고 있습니다. 연결된 엔티티를 모두 업데이트하는 양식을 설정했지만 주소가 업데이트되면 회사에 타임 스탬프를 지정할 수 있습니다. 둘의 소유자이므로 업데이트가 가능합니다.symfony2 timestampable 관련 엔티티 업데이트 포함
timestampable이 이것을 할 수 있는지 또는 내가 잘못했을 수도있는 사람이 누구인지 아시겠습니까?
<?php
// src/Amber/AtsBundle/Entity/Company.php
namespace Amber\AtsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
//...
use Doctrine\Common\Collections\ArrayCollection;
/**
* Company
*
* @ORM\Table()
* @ORM\Entity
*/
class Company
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="Address", cascade={"persist"})
* @ORM\JoinTable(name="company_addresses",
* joinColumns={@ORM\JoinColumn(name="company_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="address_id", referencedColumnName="id", unique=true)}
* )
**/
private $addresses;
public function __construct()
{
$this->addresses = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @var datetime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
Address 클래스가 아닌 많은 당신이 세터와 게터를 볼 수 있지만 나를 수 있도록 필요가 있다고 생각하지 않습니다
<?php
// src/Amber/AtsBundle/Entity/Address.php
namespace Amber\AtsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Address
*
* @ORM\Table()
* @ORM\Entity
*/
class Address
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @var datetime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
보고 :
현재 우리 회사의 클래스를 볼 수 있습니다 알고
컨트롤러
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class CompaniesController extends Controller
{
public function editAction(Request $request, $companyID)
{
$em = $this->getDoctrine()->getManager();
$company = $em->getRepository('AmberAtsBundle:Company')->find($companyID);
$passExist = 'Yes';
$form = $this->createForm(new CompanyType(), $company, array("pass_exists" => $passExist));
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('amber_ats_companies_edit', array('companyID' => $company->getId())));
}
}
}
어떤 도움을 주셔서 감사합니다 ...
명확하지 않은 점이 있으면 답변을 수락하십시오 : – nifr
다른 팁 : @ParamConverter를 정리해주세요. 귀하의 컨트롤러 -> http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html – nifr