Commit ef658842 authored by Fabien Potencier's avatar Fabien Potencier

updated docs

parent 29af1026
...@@ -627,17 +627,15 @@ Modularity ...@@ -627,17 +627,15 @@ Modularity
When your application starts to define too many controllers, you might want to When your application starts to define too many controllers, you might want to
group them logically:: group them logically::
use Silex\ControllerCollection;
// define controllers for a blog // define controllers for a blog
$blog = new ControllerCollection(); $blog = $app['controllers_factory'];
$blog->get('/', function () { $blog->get('/', function () {
return 'Blog home page'; return 'Blog home page';
}); });
// ... // ...
// define controllers for a forum // define controllers for a forum
$forum = new ControllerCollection(); $forum = $app['controllers_factory'];
$forum->get('/', function () { $forum->get('/', function () {
return 'Forum home page'; return 'Forum home page';
}); });
...@@ -650,6 +648,11 @@ group them logically:: ...@@ -650,6 +648,11 @@ group them logically::
$app->mount('/blog', $blog); $app->mount('/blog', $blog);
$app->mount('/forum', $forum); $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 ``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 main Application. So, ``/`` will map to the main home page, ``/blog/`` to the
blog home page, and ``/forum/`` to the forum home page. 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 ...@@ -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 easily. Building on the example from the middleware section, here is how you
would secure all controllers for the backend collection:: would secure all controllers for the backend collection::
$backend = new ControllerCollection(); $backend = $app['controllers_factory'];
// ensure that all controllers require logged-in users // ensure that all controllers require logged-in users
$backend->before($mustBeLogged); $backend->before($mustBeLogged);
...@@ -675,9 +678,7 @@ would secure all controllers for the backend collection:: ...@@ -675,9 +678,7 @@ would secure all controllers for the backend collection::
separate file:: separate file::
// blog.php // blog.php
use Silex\ControllerCollection; $blog = $app['controllers_factory'];
$blog = new ControllerCollection();
$blog->get('/', function () { return 'Blog home page'; }); $blog->get('/', function () { return 'Blog home page'; });
return $blog; 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