Skip to content

Instantly share code, notes, and snippets.

@enricostano
Created June 9, 2012 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enricostano/2901861 to your computer and use it in GitHub Desktop.
Save enricostano/2901861 to your computer and use it in GitHub Desktop.
AttachmentController
<?php
namespace StanoSas\Bundle\DocumentBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use StanoSas\Bundle\DocumentBundle\Entity\Attachment;
use StanoSas\Bundle\DocumentBundle\Form\AttachmentType;
class AttachmentController extends Controller
{
public function newAction($ownerObj)
{
if (!$ownerObj) { throw $this->createNotFoundException('hou'); }
$attachment = new Attachment();
$ownerObj->addAttachment($attachment);
echo $ownerObj->getName();
$form = $this->createForm(new AttachmentType(), $attachment);
return $this->render('StanoSasDocumentBundle:Attachment:form.html.twig', array(
'ownerObj' => $ownerObj,
'attachment' => $attachment,
'form' => $form->createView()
));
}
public function createAction($ownerObj)
{
$attachment = new Attachment();
$ownerObj->addAttachment($attachment);
$request = $this->getRequest();
$form = $this->createForm(new AttachmentType(), $attachment);
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()
->getEntityManager();
$em->persist($attachment);
$em->flush();
return $this->redirect($this->generateUrl('StanoSasDocumentBundle_gara_show', array( 'gid' => $ownerObj->getId() )));
}
return $this->render('StanoSasDocumentBundle:Attachment:create.html.twig', array(
'attachment' => $attachment,
'form' => $form->createView()
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment