Created
February 5, 2018 16:57
-
-
Save derrabus/444bff8199190e43482706b9b8fd0f98 to your computer and use it in GitHub Desktop.
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->register(new ServiceControllerServiceProvider()); | |
$app['my_controller'] = function($app) { | |
return new Controller\MyController($app['service_container']); | |
}; | |
$app->get('/my_route', 'my_controller: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 | |
{ | |
private $container; | |
public function __construct(ContainerInterface $container) | |
{ | |
$this->container = $container; | |
} | |
public function myAction(): string | |
{ | |
// Insert controller logic here. | |
return $this->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