- 27 Mar, 2011 20 commits
-
-
Fabien Potencier authored
-
Fabien Potencier authored
* igorw/urlgenerator: [UrlGeneratorExtension] service for generating URLs for routes
-
Fabien Potencier authored
* igorw/beforefilter-httpexception: [Application] onSilexBefore should fire on BaseHttpException
-
Igor Wiedler authored
Usage example: $app->register(new UrlGeneratorExtension()); $app->get('/hello/:name', function($name) { return "Hello $name!"; }) ->bind('hello'); $app->get('/go', function() use ($app) { $url = $app['url_generator']->generate('hello', array('name' => 'Fabien')); return $app->redirect($url); }); Thanks to @choffmeister.
-
Igor Wiedler authored
-
Igor Wiedler authored
-
Igor Wiedler authored
Sample usage: $app = new Application(); $app->register(new MonologExtension(), array( 'monolog.class_path' => __DIR__.'/vendor/monolog/src', 'monolog.logfile' => __DIR__.'/application.log', )); $app->get('/hello', function() use ($app) { $app['monolog']->addDebug('currently at hello'); return 'Hello World!'; }); $app->get('/error', function() { throw new RuntimeException('Some error'); }); $app->run();
-
Fabien Potencier authored
This is also to avoid confusion with the fluid interface we now have for controllers.
-
Fabien Potencier authored
$app->get('/{id}', function($id) { // ... })->assert('id', '\d+');
-
Fabien Potencier authored
Usage: use Silex\Application; use Silex\Extension\TwigExtension; require_once __DIR__.'/silex.phar'; $app = new Application(); $templates = array( 'hello' => 'Hello {{ name }}', ); $app->register(new TwigExtension(), array( 'twig.templates' => $templates, 'twig.class_path' => '/path/to//Twig/lib', )); $app->get('/{name}', function($name) use ($app) { return $app['twig']->render('hello', array('name' => $name)); }); $app->run();
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
Usage example: $app->register(new TwigExtension(), array( 'twig.path' => __DIR__.'/templates', 'twig.options' => array('cache' => __DIR__.'/../cache', 'debug' => true, 'strict_variables' => true), 'twig.configure' => $app->protect(function ($twig) use ($app) { $twig->addExtension(...); }) ));
-
Fabien Potencier authored
-
Fabien Potencier authored
-
- 26 Mar, 2011 9 commits
-
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
-
Fabien Potencier authored
Usage: $app = new Application(); $app->register(new TwigExtension(), array( 'twig.path' => __DIR__.'/../templates', 'twig.options' => array('cache' => __DIR__.'/../cache', 'debug' => true), )); The "app" variable is registered as a global variable, so it is accessible in all templates: $app['routing'] = new UrlGenerator(...); {{ app.routing.generate('homepage') }}
-
Fabien Potencier authored
-
Fabien Potencier authored
You can now use the app instance to store objects or parameters: $app = new Application(); $app['twig'] = new \Twig_Environment(...); $app['debug'] = true; $app->get('/', function() use ($app) { return $app['twig']->load('index.html')->render(array()); }); For sercices, you can even make them lazy loaded and/or shared: $app['twig'] = $app->asShared(function () { return \Twig_Environment(...); });
-
Fabien Potencier authored
-
Fabien Potencier authored
-
- 25 Mar, 2011 6 commits
-
-
Fabien Potencier authored
-
Igor Wiedler authored
-
Igor Wiedler authored
-
Igor Wiedler authored
-
Igor Wiedler authored
-
Igor Wiedler authored
-
- 24 Mar, 2011 3 commits
-
-
Igor Wiedler authored
-
Igor Wiedler authored
-
Igor Wiedler authored
The challenge is to allow the RouteCollection to be mutable while making it possible to set Route names. We do not want to set the route name when creating the Controller (it must be optional, adding it after the closure is ugly as hell), and RouteCollection does not allow changing route names after they have been added. The way to solve this is to add a staging area for these routes. This staging area is the ControllerCollection. All defined controllers are added to this area. Once the flush() method is called on the ControllerContainer, the controllers are frozen (no name change possible) and added as routes to the RouteContainer. If you want to make use of the RouteCollection (for example: dumping out routes to the console), you must explicitly call flush() on the ControllerCollection. There was no good way to do this implicitly. The application will also call flush() if you use handle() or run(). TLDR: a) We can now set route names b) Call getControllerCollection()->flush() before getRouteCollection() c) We must document flushing d) Bulat is awesome
-
- 22 Mar, 2011 2 commits
-
-
Fabien Potencier authored
-
Fabien Potencier authored
-