Created
June 9, 2012 17:20
-
-
Save enricostano/2901861 to your computer and use it in GitHub Desktop.
AttachmentController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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