Skip to content

Instantly share code, notes, and snippets.

@derrabus
Last active February 5, 2018 15:16
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/ded9110d60d711060b4248ecaa2c68d9 to your computer and use it in GitHub Desktop.
Save derrabus/ded9110d60d711060b4248ecaa2c68d9 to your computer and use it in GitHub Desktop.
Application-aware Silex Controller
<?php
namespace Acme\MyApp;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
$app = new Application();
$app->register(new TwigServiceProvider());
$app->get('/my_route', 'Acme\MyApp\Controller\MyController::myAction');
<?php
namespace Acme\MyApp\Controller;
use Silex\Application;
class MyController
{
public function myAction(Application $app): string
{
// Insert controller logic here.
return $app['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