controller invoke symfony code example
Example 1: symfony call another controller
public function myAction($name)
{
$response = $this->forward(
'App\Controller\OtherController::fancy',
array(
'name' => $name,
'color' => 'green',
)
);
return $response;
}
Example 2: Basic Symfony Controller
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LuckyController
{
public function number(int $max): Response
{
$number = random_int(0, $max);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}