I made two bundles. I have created an action method in each of their respective controllers.
I am trying to get result of A in B.
I have attempted to include the content of the view of what A generates in B but my include ends up missing a variable therefore I retrieve the result from forwarding it.
I read the documentation and decided to use $variable=$this->forwad(MyControllerA)
but my $variable
doesn't get any result when I read the data in the view.
I was wondering as I found no similar issue if I am doing something wrong or if I should do this differently.
Code
public function getAAction()
{
$em = $this->getDoctrine()->getManager();
$list_A = $em->getRepository('ABundle:A_Entity')->findAll();
return $list_A;
}
public function getBAction()
{
$em = $this->getDoctrine()->getManager();
$list_B = $em->getRepository('PropertyBundle:B_Entity')->findAll();
$list_A = $this->forward('A_Bundle:A_Entity:getA');
return $this->render('@B/B/getB.html.twig', array('list_B' => $list_B, 'list_A' => $list_A));
}
I found out i was wrong.
I dumped the variable as suggested by @Rendy and did way deeper research to try and understand more. it averred that forward works with response.
From there i tried manipulating the response i got but due to my lack of knowledge and despite the research i couldn't find how to retrieve the array i sent.
Therefore i converted my controller into service as follow in services.yml
of my bundle
services:
bundle_a:
class: BundleA\Controller\AController
calls:
- [ "setContainer", [ "@service_container" ] ]
If you're wondering about the last line its because when calling the container is null. That line fixed it. For more info you can look at Symfony: Why is method $this->get() not available in constructor?
Then i just called my method in the B Controller
as follow
$list_a= $this->get('bundle_a')->getAAction();
It should be $variable=$this->forwad(MyBundle:MyControllerA:myAction)
and not $variable=$this->forwad(MyControllerA)
http://symfony.com/doc/current/controller/forwarding.html
Show us the code so you can get better help