Created
July 20, 2023 13:44
-
-
Save adrienlucas/5f832d2aef49012572f6924d5538d611 to your computer and use it in GitHub Desktop.
`make:controller --standalone --invoke`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
use Symfony\Component\HttpKernel\Attribute\AsController; | |
use Symfony\Component\Routing\Annotation\Route; | |
#[AsController] | |
class WithoutTwigController | |
{ | |
#[Route('/without/twig', name: 'app_without_twig')] | |
public function __invoke(): JsonResponse | |
{ | |
return new JsonResponse([ | |
'message' => 'Welcome to your new controller!', | |
'path' => 'src/Controller/WithoutTwigController.php', | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpKernel\Attribute\AsController; | |
use Symfony\Component\Routing\Annotation\Route; | |
use Twig\Environment; | |
#[AsController] | |
class WithTwigController | |
{ | |
public function __construct( | |
private Environment $twig, | |
) { | |
} | |
#[Route('/with/twig', name: 'app_with_twig')] | |
public function __invoke(): Response | |
{ | |
return new Response($this->twig->render('with_twig.html.twig', [ | |
'controller_name' => 'WithTwigController', | |
])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment