Commit ef658842 authored by Fabien Potencier's avatar Fabien Potencier

updated docs

parent 29af1026
......@@ -627,17 +627,15 @@ Modularity
When your application starts to define too many controllers, you might want to
group them logically::
use Silex\ControllerCollection;
// define controllers for a blog
$blog = new ControllerCollection();
$blog = $app['controllers_factory'];
$blog->get('/', function () {
return 'Blog home page';
});
// ...
// define controllers for a forum
$forum = new ControllerCollection();
$forum = $app['controllers_factory'];
$forum->get('/', function () {
return 'Forum home page';
});
......@@ -650,6 +648,11 @@ group them logically::
$app->mount('/blog', $blog);
$app->mount('/forum', $forum);
.. note::
``$app['controllers_factory']`` is a factory that returns a new instance
of ``ControllerCollection`` when used.
``mount()`` prefixes all routes with the given prefix and merges them into the
main Application. So, ``/`` will map to the main home page, ``/blog/`` to the
blog home page, and ``/forum/`` to the forum home page.
......@@ -664,7 +667,7 @@ Another benefit is the ability to apply settings on a set of controllers very
easily. Building on the example from the middleware section, here is how you
would secure all controllers for the backend collection::
$backend = new ControllerCollection();
$backend = $app['controllers_factory'];
// ensure that all controllers require logged-in users
$backend->before($mustBeLogged);
......@@ -675,9 +678,7 @@ would secure all controllers for the backend collection::
separate file::
// blog.php
use Silex\ControllerCollection;
$blog = new ControllerCollection();
$blog = $app['controllers_factory'];
$blog->get('/', function () { return 'Blog home page'; });
return $blog;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment