symfony2 form is not displaying

symfony, symfony-2.1, symfony-2.2

Solution

You don't need to pass `$request` to your action and you don't need to put it in your route. The request object is available in global context. So

task_new:
    pattern:  /task-new
    defaults: { _controller: BannerTestBundle:Default:new}

You can either leave it this way

public function newAction(Request $request)

or have

public function newAction()

and access request object like this

$request  = $this->getRequest();

Problem

I am learning symfony2 and i have created one form in controller which is as bellow. the controller file as DefaultController.php ``` namespace Banner\TestBundle\Controller; use Banner\TestBundle\Entity\Contact; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Banner\TestBundle\Entity\Task; use Symfony\Components\HttpFoundation\Request; class DefaultController extends Controller { public function newAction(Request $request) { echo "The controller is called "; $task = new Task(); $task->setTask("Write a blog Post "); $task->setDueDate(new DateTime('tomorrow')); $form = $this->createFormBuilder($task) ->add('task','text ') ->add('duedate','date') ->getForm(); return $this->render('BannerTestBundle:default:zoo.html.twig',array('form'=>$form->createView())); } } ``` my routing file is as below. routing.yml ``` task_new: pattern: /task/{request} defaults: { _controller: BannerTestBundle:Default:new} ``` and the zoo.html.twig file is as bellow. ``` {% extends '::page.html.twig' %} {% block title %}The Zoo{% endblock %} {% block content %} <form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input type="submit"> </form> {% endblock %} ``` as i am passing the "task/GET" in my url it will shows the 'Request does not exist. error 500'. what i basically want to do is when i pass the url the zoo.html.twig will be called. i want to display the form in zoo.html.twig.

Original source