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
8ac1c044
Commit
8ac1c044
authored
Jan 10, 2013
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docs] Add a section about controllers in classes to usage doc
parent
d6243e37
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
5 deletions
+30
-5
doc/usage.rst
doc/usage.rst
+30
-5
No files found.
doc/usage.rst
View file @
8ac1c044
...
...
@@ -123,10 +123,6 @@ import local variables of that function.
The return value of the closure becomes the content of the page.
There is also an alternate way for defining controllers using a class method.
The syntax for that is ``ClassName::methodName``. Static methods are also
possible.
Example GET route
~~~~~~~~~~~~~~~~~
...
...
@@ -383,6 +379,35 @@ really be used. You can give a route a name by calling ``bind`` on the
It only makes sense to name routes if you use providers that make use of
the ``RouteCollection``.
Controllers in classes
~~~~~~~~~~~~~~~~~~~~~~
If you don't want to use anonymous functions, you can also define your
controllers as methods. By using the ``ControllerClass::methodName`` syntax,
you can tell Silex to lazily create that controller class for you::
$app->get('/', 'Igorw\Foo::bar');
use Symfony\Component\HttpFoundation\Request;
namespace Igorw
{
class Foo
{
public function bar(Request $request)
{
...
}
}
}
This will load the ``Igorw\Foo`` class on demand, create an instance and call
the ``bar`` method to get the response. You can use ``Request`` and
``Silex\Application`` type hints to get ``$request`` and ``$app`` injected.
For an even stronger separation between Silex and your controllers, you can
:doc:`define your controllers as services <providers/service_controller>`.
Global Configuration
--------------------
...
...
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