Symfony - passign fields values to a template

Hello,

In my form submission controller, I have :

return $this->redirectToRoute('TaskCreated', array('task' => $task,));

The routing works well through ::

TaskCreated:
    path:     /TaskCreated
    defaults: { _controller: AppBundle:TaskCreated:taskCreated }

In my TaskCreated controller, I try to retrieve the fields value to transfer them to a dedicated template :

<?php
// src/AppBundle/Controller/TaskClassController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class TaskCreatedController extends Controller
	{
    public function taskCreatedAction($task)
	    {
        return $this->render('taskCreated.html.twig', array('task' => $task,));
        }
    } 

But symfony says that “Controller “AppBundle\Controller\TaskCreatedController::taskCreatedAction()” requires that you provide a value for the “$task” argument (because there is no default value or because there is a non optional argument after this one).” I guess it means that $task is empty when calling taskCreatedAction()…

So how can I retrieve my field values ?

Best regards,

MC

public function taskCreatedAction(Request $request) {
    $task = $request->query->get('task');

When you get a chance, read up a bit on routes and placeholders and default values.

And I assume that $task is a simple value. Not an object? If it is an object then you need to go back and work through the example in the manual.

Thanks (again) ahundiak,

$task is an object. I’ll do some readings. Symfony is definitely not an easy party.

Start here:

You also need a reasonable understanding of object oriented programming.

Symfony is very straight forward as long as you have the basics of web applications.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.