Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Acme\TestBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\Request;
- use Acme\TestBundle\Entity\Shouter;
- /**
- * @Route("/acme")
- */
- class HelloDbController extends Controller {
- /**
- * @Route("/insert_db/{msg}", name="hai_insert_db")
- */
- public function insertdbAction($msg = 'hallo world ')
- {
- $shouter = new Shouter();
- $shouter->setMessages($msg);
- $shouter->setDescription("lorema ipsuma");
- $shouter->setCreatedAt(new \DateTime("now"));
- $shouter->setUpdatedAt(new \DateTime("now"));
- $em = $this->getDoctrine()->getManager();
- $em->persist($shouter);
- $em->flush();
- return new Response('Created shouter id '.$shouter->getId());
- }
- /**
- * @Route("/hai_db", name="hai_db")
- */
- public function greatingAction()
- {
- $repository = $this->getDoctrine()->getRepository('AcmeTestBundle:Shouter');
- $shouters = $repository->findAll();
- $html = $this->container
- ->get('templating')
- ->render(
- 'AcmeTestBundle:Hoi:list.html.twig',
- array('shouters' => $shouters)
- );
- return new Response($html);
- }
- /**
- *
- * @Route("/hai_form_db", name="hai_form_add_db1")
- */
- public function formAdd1Action(Request $request) {
- $shouter = new Shouter();
- $form = $this->createFormBuilder($shouter)
- ->add('messages', 'text')
- ->add('description', 'text')
- ->add('createdAt', 'datetime')
- ->add('updatedat', 'datetime')
- ->add('save', 'submit', array('label' => 'Create Hello World'))
- ->getForm();
- //handle save
- $form->handleRequest($request);
- if ($form->isValid()) {
- $data = $form->getData();
- $em = $this->getDoctrine()->getManager();
- $em->persist($data);
- $em->flush();
- //return $this->redirect('task_success');
- }
- return $this->render('AcmeTestBundle:Hoi:add.html.twig', array(
- 'form' => $form->createView(),
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement