0
votes

I seem to have come across an issue with Symfony 2 that I have not seen before (or more likley im missing something really obvious).

I had a route which took no parameters and worked perfectly, linking up to the controller and displaying the correct view. I then updated the route to take a single parameter like so:

# Note routing
    gibbo_dummy_notes_Add:
        pattern:  /notes/add/{notebook}
        defaults: { _controller: GibboDummyBundle:Note:add, notebook: 0}
        requirements:
                _method:  POST|GET

However if I now try and access this route notes/add/test I get the error The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?. If I remove the parameter it works perfectly notes/add.

This setup is exactly the same as the rest of the routes that use parameters in my app.

The action in the controller definitely returns a response object. If I place a die('test'); at the top of the action and remove the parameter from the URL I reach the die statement and see 'test', but if I add the parameter to the URL it shows the error, so its clearly not reaching my controller or action when including the parameter but as far as I can tell the route is setup correctly, and im not getting the normal route not defined error I would expect to see if there was an issue with the url.

Im running it under the dev environment and I have tried other browsers / cleared cache etc. The action inside the controller NoteController looks like

public function addAction($notebook)
{

    $pageTitle = 'Note';


    $form = $this->createForm(new NoteType(), null, array(
        'validation_groups' => array('add')
    ));

    $request = $this->getRequest();

    if ($request->isMethod('POST')) {
        $form->bind($request);

        if ($form->isValid()) {

            /** @var $em \Doctrine\ORM\EntityManager */
            $em = $this->getDoctrine()->getManager();

            /** @var $note Note */
            $note = $form->getData();
            $note->setNotebook();

            $em->persist($note);
            $em->flush();

            return $this->redirect($this->generateUrl('gibbo_dummy_note_View'));
        }
    }

    return $this->render('GibboDummyBundle:Note:new.html.twig', array(
        'pageTitle' => $pageTitle,
        'form_add'  => $form->createView(),
        'selected' => 'codebooks'
    ));


}

Can anyone shed some light about what I might be doing wrong?

1
My guess would be that it matches another route for a strange reason. You can go in the profiler to see which route it matched from the router!Hugo Dozois
in the root directory php app/console router:debug look for the route and make sure it goes to the right placeThomas Potaire
Thanks for the response router:debug showed nothing unusual: gibbo_codekeeper_notes_Add POST|GET /notes/add/{notebook}Ben_hawk
oh and theres no duplicates eitherBen_hawk
Try setting the notebook param default to other value besides 0. (null, for example).brpaz

1 Answers

0
votes

Please add the controller code for gibbo_dummy_note_View route.

Most likely, your redirection ends up in a bad controller method - the one that does not have return statement