I have 2 actions in the same controller. I find problem in passing posted values from the 1st action to the the 2nd one. I tried to use forward method http://symfony.com/doc/current/controller/forwarding.html
BTW both actions (the 'forwarding' and the 'forwarded to') have forms with submissions.
Problem is I couldn't access the variable " $param1 " in the second action. It always goes null.
Is there anything I have missed here?
Here is my code:
This is the 1st action:
/**
*
* @Route("/new1", name="command_check1")
*/
public function check1Action(Request $request)
{
$host = new Host();
$form = $this->createFormBuilder($host)
->add("iPaddress", TextType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$a= $form["iPaddress"]->getData(); //$a= '127.0.0.1'
**$this->forward('AcmeBundle:Command:check2', array('param1' => $a));**
if($this->pingAction($a)==true){
return $this->redirectToRoute('command_check2'); }
}
return $this->render('host/new1.html.twig', array(
'host' => $host,
'form' => $form->createView(),));
}
This is the 2nd action:
/**
*
* @Route("/new2", name="command_check2")
*/
public function check2Action(Request $request, **$param1**)
{
**var_dump($param1); // here i can get the posted value $param1= '127.0.0.1'**
$host = new Host();
$form = $this->createFormBuilder($host)
->add("login", TextType::class)
->add("password", TextType::class)
->getForm();
$form->handleRequest($request);
**var_dump($param1); // until here it works good $param1= '127.0.0.1'**
if ($form->isSubmitted() && $form->isValid())
{
**// the problem is here after submitting the 2nd form
var_dump($param1); // $param= null**
$b= $form["login"]->getData();
$c= $form["password"]->getData();
}
return $this->render('host/new2.html.twig', array(
'host' => $host,
'form' => $form->createView(),));
}