Skip to content

Instantly share code, notes, and snippets.

@aginanjar
Last active August 29, 2015 14:12
Show Gist options
  • Save aginanjar/bafbadd2a2ad24b5df70 to your computer and use it in GitHub Desktop.
Save aginanjar/bafbadd2a2ad24b5df70 to your computer and use it in GitHub Desktop.
Menampilkan xml untuk entitas, Entity class, dan Admin.
// --- src/App/Bundle/Resources/config/doctrine/EmailTemplate.orm.xml --- //
// Email Template orm xml
<one-to-many field="attachments" target-entity="EmailTemplateAttachments" mapped-by="idEmailTemplate" orphan-removal="true">
<cascade>
<cascade-persist/>
</cascade>
<join-columns>
<join-column name="id" referenced-column-name="id_email_template"/>
</join-columns>
<gedmo:versioned/>
</one-to-many>
// Email Template Attach orm xml
<many-to-one field="idEmailTemplate" target-entity="EmailTemplate" inversed-by="attachments">
<join-columns>
<join-column name="id_email_template" referenced-column-name="id" nullable="false"/>
</join-columns>
<gedmo:versioned/>
</many-to-one>
// --- src/App/Bundle/Entity/EmailTemplate.php --- //
// EmailTemplate Entity
/**
*
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Application\Sonata\UserBundle\Entity\EmailTemplateAttachments", mappedBy="idEmailTemplate")
*/
private $attachments;
public function setAttachments($attachments) {
$this->attachments = new ArrayCollection();
if (count($attachments) > 0) {
foreach ($attachments as $attachment) {
$this->addAttachment($attachment);
}
}
return $this;
}
/**
* Get attachments
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAttachments() {
return $this->attachments;
}
/**
* Add items
*
* @param \Application\Sonata\UserBundle\Entity\EmailTemplateAttachments $attachments
* @return EmailTemplate
*/
public function addAttachment(\Application\Sonata\UserBundle\Entity\EmailTemplateAttachments $attachments)
{
$attachments->setIdEmailTemplate($this);
$this->attachments[] = $attachments;
return $this;
}
/**
* Remove items
*
* @param \Application\Sonata\UserBundle\Entity\EmailTemplateAttachments $attachments
*/
public function removeAttachment(\Application\Sonata\UserBundle\Entity\EmailTemplateAttachments $attachments)
{
$this->attachments->removeElement($attachments);
}
// --- src/App/Bundle/Entity/EmailTemplateAttachments.php --- //
/**
* @var \Application\Sonata\UserBundle\Entity\EmailTemplate
*
* @ORM\ManyToOne(targetEntity="EmailTemplate", inversedBy="attachments")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_email_template", referencedColumnName="id", nullable=false)
* })
*/
private $idEmailTemplate;
// --- src/App/Bundle/Admin/EmailTemplate.orm.xml --- //
// Email Template Admin
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
...
->add('attachments', 'sonata_type_collection',array(
'required' => false,
'label'=> 'Choose individual file'
))
...
}
// --- src/App/Bundle/Admin/EmailTemplateAttachments.orm.xml --- //
// Email Template Attachment Admin
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
...
->add('path','file'))
...
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment