Created
February 5, 2018 16:48
-
-
Save derrabus/e2d56691c4523aa419b50ae43143bcf0 to your computer and use it in GitHub Desktop.
Container-aware Silex Controller with PSR-11
This file contains hidden or 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 Acme\MyApp; | |
use Rabus\Psr11ServiceProvider\Psr11ServiceProvider; | |
use Silex\Application; | |
use Silex\Provider\TwigServiceProvider; | |
$app = new Application(); | |
$app->register(new TwigServiceProvider()); | |
$app->register(new Psr11ServiceProvider()); | |
$app->get('/my_route', 'Acme\MyApp\Controller\MyController::myAction'); |
This file contains hidden or 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 Acme\MyApp\Controller; | |
use Psr\Container\ContainerInterface; | |
class MyController | |
{ | |
public function myAction(ContainerInterface $container): string | |
{ | |
// Insert controller logic here. | |
return $container->get('twig') | |
->render('my_template.html.twig', $parameters); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment