Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is the simple silex app.
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => dirname(__DIR__) . '/src/views'
));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['security.firewalls'] = array(
'admin' => array(
'pattern' => '^/admin/?',
'form' => array('login_path' => '/login', 'check_path' => '/admin/login_check'),
'logout' => array('logout_path' => '/logout'),
'users' => array(
'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
),
),
);
$app->get('/', function(Request $request) use ($app) {
return new Response('index', 200);
});
$app->get('/admin', function(Request $request) use ($app) {
return new Response('admin', 200);
});
$app->get('/logout', function() use ($app) {
return new Response('logout', 200);
});
$app->get('/login', function(Request $request) use ($app) {
return $app['twig']->render('login.twig', array(
'error' => $app['security.last_error']($request),
'last_username' => $app['session']->get('_security.last_username'),
));
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.