Commit 1f12c783 authored by Igor Wiedler's avatar Igor Wiedler

[docs] move extension documentation to sub-directory

parent 0fc426a2
...@@ -30,136 +30,8 @@ Included extensions ...@@ -30,136 +30,8 @@ Included extensions
There are a few extensions that you get out of the box. There are a few extensions that you get out of the box.
All of these are within the ``Silex\Extension`` namespace. All of these are within the ``Silex\Extension`` namespace.
Monolog * :doc:`MonologExtension <extensions/monolog>`
~~~~~~~ * :doc:`TwigExtension <extensions/twig>`
The *MonologExtension* provides a default logging mechanism
through Jordi Boggiano's `Monolog <https://github.com/Seldaek/monolog>`_
library.
It will log requests and errors and allow you to add debug
logging to your application, so you don't have to use
``var_dump`` so much anymore. You can use the grown-up
version called ``tail -f``.
**Parameters**
* **monolog.logfile**: File where logs are written to.
* **monolog.class_path** (optional): Path to where the
Monolog library is located.
* **monolog.level** (optional): Level of logging defaults
to ``DEBUG``. Must be one of ``Logger::DEBUG``, ``Logger::INFO``,
``Logger::WARNING``, ``Logger::ERROR``. ``DEBUG`` will log
everything, ``INFO`` will log everything except ``DEBUG``,
etc.
* **monolog.name** (optional): Name of the monolog channel,
defaults to ``myapp``.
**Services**
* **monolog**: The monolog logger instance.
Example usage::
$app['monolog']->addDebug('Testing the Monolog logging.');
* **monolog.configure**: Protected closure that takes the
logger as an argument. You can override it if you do not
want the default behavior.
**Registering**
Make sure you place a copy of *Monolog* in the ``vendor/monolog``
directory.
::
use Silex\Extension\MonologExtension;
$app->register(new MonologExtension(), array(
'monolog.logfile' => __DIR__.'/development.log',
'monolog.class_path' => __DIR__.'/vendor/monolog/src',
));
Twig
~~~~
The *TwigExtension* provides integration with the `Twig
<http://www.twig-project.org/>`_ template engine.
**Parameters**
* **twig.path**: Path to the directory containing twig template
files.
* **twig.templates** (optional): If this option is provided
you don't have to provide a ``twig.path``. It is an
associative array of template names to template contents.
Use this if you want to define your templates inline.
* **twig.options** (optional): An associative array of twig
options. Check out the twig documentation for more information.
* **twig.class_path** (optional): Path to where the Twig
library is located.
* **symfony_bridges** (optional): Set this to true if you want
to integrate the ``UrlGeneratorExtension`` and the
``TranslationExtension`` with Twig. This requires loading
Symfony2 ``Bridge`` classes which include those Twig extensions.
**Services**
* **twig**: The ``Twig_Environment`` instance, you will only
need to use this.
* **twig.configure**: Protected closure that takes the twig
environment as an argument. You can use it to add more
custom globals.
* **twig.loader**: The loader for twig templates which uses
the ``twig.path`` and the ``twig.templates`` options. You
can also replace the loader completely.
**Registering**
Make sure you place a copy of *Twig* in the ``vendor/twig``
directory.
::
use Silex\Extension\TwigExtension;
$app->register(new TwigExtension(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
));
**Usage**
The Twig extension provides a ``twig`` service.
::
$app->get('/hello/{name}', function($name) use ($app) {
return $app['twig']->render('hello.twig', array(
'name' => $name,
));
});
This will render a file named ``views/hello.twig``.
It also registers the application as a global named
``app``. So you can access any services from within your
view. For example to access ``$app['request']->getHost()``,
just put this in your template:
.. code-block:: jinja
{{ app.request.host }}
Creating an extension Creating an extension
--------------------- ---------------------
......
Silex
=====
.. toctree::
:maxdepth: 2
monolog
twig
Monolog
=======
The *MonologExtension* provides a default logging mechanism
through Jordi Boggiano's `Monolog <https://github.com/Seldaek/monolog>`_
library.
It will log requests and errors and allow you to add debug
logging to your application, so you don't have to use
``var_dump`` so much anymore. You can use the grown-up
version called ``tail -f``.
Parameters
----------
* **monolog.logfile**: File where logs are written to.
* **monolog.class_path** (optional): Path to where the
Monolog library is located.
* **monolog.level** (optional): Level of logging defaults
to ``DEBUG``. Must be one of ``Logger::DEBUG``, ``Logger::INFO``,
``Logger::WARNING``, ``Logger::ERROR``. ``DEBUG`` will log
everything, ``INFO`` will log everything except ``DEBUG``,
etc.
* **monolog.name** (optional): Name of the monolog channel,
defaults to ``myapp``.
Services
--------
* **monolog**: The monolog logger instance.
Example usage::
$app['monolog']->addDebug('Testing the Monolog logging.');
* **monolog.configure**: Protected closure that takes the
logger as an argument. You can override it if you do not
want the default behavior.
Registering
-----------
Make sure you place a copy of *Monolog* in the ``vendor/monolog``
directory.
::
use Silex\Extension\MonologExtension;
$app->register(new MonologExtension(), array(
'monolog.logfile' => __DIR__.'/development.log',
'monolog.class_path' => __DIR__.'/vendor/monolog/src',
));
Twig
====
The *TwigExtension* provides integration with the `Twig
<http://www.twig-project.org/>`_ template engine.
Parameters
----------
* **twig.path**: Path to the directory containing twig template
files.
* **twig.templates** (optional): If this option is provided
you don't have to provide a ``twig.path``. It is an
associative array of template names to template contents.
Use this if you want to define your templates inline.
* **twig.options** (optional): An associative array of twig
options. Check out the twig documentation for more information.
* **twig.class_path** (optional): Path to where the Twig
library is located.
* **symfony_bridges** (optional): Set this to true if you want
to integrate the ``UrlGeneratorExtension`` and the
``TranslationExtension`` with Twig. This requires loading
Symfony2 ``Bridge`` classes which include those Twig extensions.
Services
--------
* **twig**: The ``Twig_Environment`` instance, you will only
need to use this.
* **twig.configure**: Protected closure that takes the twig
environment as an argument. You can use it to add more
custom globals.
* **twig.loader**: The loader for twig templates which uses
the ``twig.path`` and the ``twig.templates`` options. You
can also replace the loader completely.
Registering
-----------
Make sure you place a copy of *Twig* in the ``vendor/twig``
directory.
::
use Silex\Extension\TwigExtension;
$app->register(new TwigExtension(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
));
Usage
-----
The Twig extension provides a ``twig`` service.
::
$app->get('/hello/{name}', function($name) use ($app) {
return $app['twig']->render('hello.twig', array(
'name' => $name,
));
});
This will render a file named ``views/hello.twig``.
It also registers the application as a global named
``app``. So you can access any services from within your
view. For example to access ``$app['request']->getHost()``,
just put this in your template:
.. code-block:: jinja
{{ app.request.host }}
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