У меня проблема в том, что переадресация запросов на другой контроллер не работает.
Я пробовал решение / пример из документации Symfony (https://symfony.com/doc/current/controller/forwarding.html).
IndexController.php
<?php
namespace App\Controller;
use App\Controller\OeffnungController;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class IndexController extends AbstractController
{
/**
* @Route("/")
*/
public function index($thisname)
{
$thisname = "TEST";
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
'pagetype' => 'index',
'pageurl' => "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
]);
}
}
?>
OeffnungController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Offnungszeiten;
use App\Controller\IndexController;
class OeffnungController extends AbstractController
{
public function show($thisname)
{
$product = $this->getDoctrine()
->getRepository(Offnungszeiten::class)
->findOneBy(['name' => 'TESTPRODUCT']);
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '
);
}
$response = $this->forward('App\Controller\IndexController::index', [
'thisname' => $product->getName(),
]);
return $response;
}
}
?>
Я получил следующую ошибку
Could not resolve argument $thisname of "App\Controller\IndexController::index()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?