Skip to content

Instantly share code, notes, and snippets.

@derrabus
Created February 5, 2018 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derrabus/e2d56691c4523aa419b50ae43143bcf0 to your computer and use it in GitHub Desktop.
Save derrabus/e2d56691c4523aa419b50ae43143bcf0 to your computer and use it in GitHub Desktop.
Container-aware Silex Controller with PSR-11
<?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');
<?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