Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
02a39976
Commit
02a39976
authored
Nov 05, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved the modularity section of the docs to its own section
parent
cbc769ce
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
74 deletions
+74
-74
doc/index.rst
doc/index.rst
+1
-0
doc/modularity.rst
doc/modularity.rst
+73
-0
doc/usage.rst
doc/usage.rst
+0
-74
No files found.
doc/index.rst
View file @
02a39976
...
@@ -7,6 +7,7 @@ Silex
...
@@ -7,6 +7,7 @@ Silex
intro
intro
usage
usage
middlewares
middlewares
modularity
services
services
providers
providers
testing
testing
...
...
doc/modularity.rst
0 → 100644
View file @
02a39976
Modularity
==========
When your application starts to define too many controllers, you might want to
group them logically::
// define controllers for a blog
$blog = $app['controllers_factory'];
$blog->get('/', function () {
return 'Blog home page';
});
// ...
// define controllers for a forum
$forum = $app['controllers_factory'];
$forum->get('/', function () {
return 'Forum home page';
});
// define "global" controllers
$app->get('/', function () {
return 'Main home page';
});
$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.
.. caution::
When mounting a route collection under ``/blog``, it is not possible to
define a route for the ``/blog`` URL. The shortest possible URL is
``/blog/``.
.. note::
When calling ``get()``, ``match()``, or any other HTTP methods on the
Application, you are in fact calling them on a default instance of
``ControllerCollection`` (stored in ``$app['controllers']``).
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 = $app['controllers_factory'];
// ensure that all controllers require logged-in users
$backend->before($mustBeLogged);
.. tip::
For a better readability, you can split each controller collection into a
separate file::
// blog.php
$blog = $app['controllers_factory'];
$blog->get('/', function () { return 'Blog home page'; });
return $blog;
// app.php
$app->mount('/blog', include 'blog.php');
Instead of requiring a file, you can also create a :doc:`Controller
provider </providers#controllers-providers>`.
doc/usage.rst
View file @
02a39976
...
@@ -531,80 +531,6 @@ round-trip to the browser (as for a redirect), use an internal sub-request::
...
@@ -531,80 +531,6 @@ round-trip to the browser (as for a redirect), use an internal sub-request::
$request = Request::create($app['url_generator']->generate('hello'), 'GET');
$request = Request::create($app['url_generator']->generate('hello'), 'GET');
Modularity
----------
When your application starts to define too many controllers, you might want to
group them logically::
// define controllers for a blog
$blog = $app['controllers_factory'];
$blog->get('/', function () {
return 'Blog home page';
});
// ...
// define controllers for a forum
$forum = $app['controllers_factory'];
$forum->get('/', function () {
return 'Forum home page';
});
// define "global" controllers
$app->get('/', function () {
return 'Main home page';
});
$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.
.. caution::
When mounting a route collection under ``/blog``, it is not possible to
define a route for the ``/blog`` URL. The shortest possible URL is
``/blog/``.
.. note::
When calling ``get()``, ``match()``, or any other HTTP methods on the
Application, you are in fact calling them on a default instance of
``ControllerCollection`` (stored in ``$app['controllers']``).
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 = $app['controllers_factory'];
// ensure that all controllers require logged-in users
$backend->before($mustBeLogged);
.. tip::
For a better readability, you can split each controller collection into a
separate file::
// blog.php
$blog = $app['controllers_factory'];
$blog->get('/', function () { return 'Blog home page'; });
return $blog;
// app.php
$app->mount('/blog', include 'blog.php');
Instead of requiring a file, you can also create a :doc:`Controller
provider </providers#controllers-providers>`.
JSON
JSON
----
----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment