2011-02-07 07:48:44 +01:00
|
|
|
# Director
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
`[api:Director]` is the first step in the "execution pipeline". It parses the
|
|
|
|
URL, matching it to one of a number of patterns, and determines the controller,
|
|
|
|
action and any argument to be used. It then runs the controller, which will
|
|
|
|
finally run the viewer and/or perform processing steps.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-05-09 14:26:29 +02:00
|
|
|
## Request processing
|
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
The `[api:Director]` is the entry point in Silverstring Framework for processing
|
|
|
|
a request. You can read through the execution steps in `[api:Director]``::direct()`,
|
|
|
|
but in short
|
2012-05-09 14:26:29 +02:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
* File uploads are first analysed to remove potentially harmful uploads (this
|
|
|
|
will likely change!)
|
2012-05-09 14:26:29 +02:00
|
|
|
* The `[api:SS_HTTPRequest]` object is created
|
|
|
|
* The session object is created
|
2012-06-30 05:19:36 +02:00
|
|
|
* The `[api:Injector]` is first referenced, and asks the registered `[api:RequestProcessor]`
|
|
|
|
to pre-process the request object. This allows for analysis of the current
|
|
|
|
request, and allow filtering of parameters etc before any of the core of the
|
|
|
|
application executes.
|
2012-05-09 14:26:29 +02:00
|
|
|
* The request is handled and response checked
|
2012-06-30 05:19:36 +02:00
|
|
|
* The `[api:RequestProcessor]` is called to post-process the request to allow
|
|
|
|
further filtering before content is sent to the end user
|
2012-05-09 14:26:29 +02:00
|
|
|
* The response is output
|
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
The framework provides the ability to hook into the request both before and
|
|
|
|
after it is handled to allow developers to bind in their own custom pre- or
|
|
|
|
post- request logic; see the `[api:RequestFilter]` to see how this can be used
|
|
|
|
to authenticate the request before the request is handled.
|
|
|
|
|
|
|
|
## Routing
|
2012-05-09 14:26:29 +02:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
You can influence the way URLs are resolved in the following ways
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
1. Adding rules to `[api:Director]` in `<yourproject>/_config/routes.yml`
|
|
|
|
2. Adding rules to `[api:Director]` in `<yourproject>/_config.php (deprecated)
|
|
|
|
3. Adding rules in your extended `[api:Controller]` class via the *$url_handlers*
|
|
|
|
static variable
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
See [controller](/topics/controller) for examples and explanations on how the
|
|
|
|
rules get processed for those methods.
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
### Routing Rules
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
SilverStripe comes with certain rules which map a URI to a `[api:Controller]`
|
|
|
|
class (e.g. *dev/* -> DevelopmentAdmin). These routes are either stored in
|
|
|
|
a routes.yml configuration file located a `_config` directory or inside a
|
|
|
|
`_config.php` file (deprecated).
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
To add your own custom routes for your application create a routes.yml file
|
|
|
|
in `<yourproject>/_config/routes.yml` with the following format:
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
:::yaml
|
|
|
|
---
|
|
|
|
Name: customroutes
|
|
|
|
After: framework/routes#coreroutes
|
|
|
|
---
|
|
|
|
Director:
|
|
|
|
rules:
|
|
|
|
'subscriptions/$Action' : 'SubscriptionController'
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
The [Controller](/topics/controller) documentation has a wide range of examples
|
|
|
|
and explanations on how the rules get processed for those methods.
|
|
|
|
|
|
|
|
See:
|
|
|
|
|
|
|
|
* [framework/_config/routes.yml](https://github.com/silverstripe/sapphire/blob/master/_config/routes.yml)
|
|
|
|
* [cms/_config/routes.yml](https://github.com/silverstripe/silverstripe-cms/blob/master/_config/routes.yml)
|
|
|
|
|
|
|
|
|
|
|
|
## Best Practices
|
2011-02-07 07:48:44 +01:00
|
|
|
|
2012-06-30 05:19:36 +02:00
|
|
|
* Checking for an Ajax-Request: Use Director::is_ajax() instead of checking
|
|
|
|
for $_REQUEST['ajax'].
|
2011-02-07 07:48:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Links
|
|
|
|
|
2011-03-08 22:05:51 +01:00
|
|
|
* See `[api:ModelAsController]` class for details on controller/model-coupling
|
2011-02-07 07:48:44 +01:00
|
|
|
* See [execution-pipeline](/reference/execution-pipeline) for custom routing
|
|
|
|
|
|
|
|
## API Documentation
|
|
|
|
`[api:Director]`
|