Created
April 17, 2011 14:17
-
-
Save arghav/924064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Flock\MainBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Flock\MainBundle\Form\EventForm; | |
use Flock\MainBundle\Entity\Event; | |
class DefaultController extends Controller | |
{ | |
/** | |
* @extra:Route("/", name="_home") | |
*/ | |
public function indexAction(Event $event) | |
{ | |
$em = $this->get('doctrine.orm.default_entity_manager'); | |
$factory = $this->get('form.factory'); | |
$form = $factory->create(new EventForm()); | |
$form->setData($event); | |
if ($this->get('request')->getMethod() === 'POST') { | |
$form->bindRequest($this->get('request')); | |
if ($form->isValid()) { | |
$em->persist($event); | |
$em->flush(); | |
return new RedirectResponse($this->generateUrl('_home')); | |
} | |
} | |
return $this->render('FlockMainBundle:Default:index.html.twig', array( | |
'form' => $form->createView(), | |
)); | |
} | |
} |
This file contains hidden or 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 | |
/** | |
* Created by amalraghav <[email protected]> | |
* Date: 17/04/11 | |
*/ | |
namespace Flock\MainBundle\Entity; | |
/** | |
* @orm:Entity | |
* @orm:Table(name="events") | |
*/ | |
class Event | |
{ | |
/** | |
* @orm:Id | |
* @orm:Column(type="integer") | |
* @orm:GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @orm:Column(type="string", length="255") | |
*/ | |
protected $event_name; | |
/** | |
* @orm:Column(type="text") | |
*/ | |
protected $event_details; | |
/** | |
* Get id | |
* | |
* @return integer $id | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set event_name | |
* | |
* @param string $eventName | |
*/ | |
public function setEventName($eventName) | |
{ | |
$this->event_name = $eventName; | |
} | |
/** | |
* Get event_name | |
* | |
* @return string $eventName | |
*/ | |
public function getEventName() | |
{ | |
return $this->event_name; | |
} | |
/** | |
* Set event_details | |
* | |
* @param text $eventDetails | |
*/ | |
public function setEventDetails($eventDetails) | |
{ | |
$this->event_details = $eventDetails; | |
} | |
/** | |
* Get event_details | |
* | |
* @return text $eventDetails | |
*/ | |
public function getEventDetails() | |
{ | |
return $this->event_details; | |
} | |
} |
This file contains hidden or 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 | |
/** | |
* Created by amalraghav <[email protected]> | |
* Date: 17/04/11 | |
*/ | |
namespace Flock\MainBundle\Form; | |
use Symfony\Component\Form\FormBuilder; | |
use Symfony\Component\Form\Type\AbstractType; | |
class EventForm extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('event_name') | |
->add('event_details') | |
->end(); | |
} | |
public function getDefaultOptions(array $options) | |
{ | |
return array( | |
'data_class' => 'Flock\MainBundle\Entity\Event', | |
); | |
} | |
public function getName() | |
{ | |
return 'eventform'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment