Flight is designed to be an extensible framework. The framework comes with a set of default methods and components, but it allows you to map your own methods, register your own classes, or even override existing classes and methods.
## Mapping Methods
### Mapping Methods
To map your own custom method, you use the `map` function:
To register your own class, you use the `register` function:
@ -271,7 +271,7 @@ $new = Flight::db(false);
Keep in mind that mapped methods have precedence over registered classes. If you declare both using the same name, only the mapped method will be invoked.
# Overriding
## Overriding
Flight allows you to override its default functionality to suit your own needs, without having to modify any code.
@ -298,7 +298,7 @@ $myrouter = Flight::router();
Framework methods like `map` and `register` however cannot be overridden. You will get an error if you try to do so.
# Filtering
## Filtering
Flight allows you to filter methods before and after they are called. There are no predefined hooks you need to memorize. You can filter any of the default framework methods as well as any custom methods that you've mapped.
Note, core methods such as `map` and `register` cannot be filtered because they are called directly and not invoked dynamically.
# Variables
## Variables
Flight allows you to save variables so that they can be used anywhere in your application.
@ -415,7 +415,7 @@ Flight also uses variables for configuration purposes.
Flight::set('flight.log_errors', true);
```
# Views
## Views
Flight provides some basic templating functionality by default. To display a view template call the `render` method with the name of the template file and optional template data:
@ -453,7 +453,7 @@ By default Flight will look for a `views` directory for template files. You can
It is common for websites to have a single layout template file with interchanging content. To render content to be used in a layout, you can pass in an optional parameter to the `render` method.
@ -509,7 +509,7 @@ The output would be:
</html>
```
## Custom Views
### Custom Views
Flight allows you to swap out the default view engine simply by registering your own view class. Here's how you would use the [Smarty](http://www.smarty.net/) template engine for your views:
You can redirect the current request by using the `redirect` method and passing in a new URL:
@ -583,7 +583,7 @@ You can redirect the current request by using the `redirect` method and passing
Flight::redirect('/new/location');
```
# Requests
## Requests
Flight encapsulates the HTTP request into a single object, which can be accessed by doing:
@ -625,11 +625,11 @@ Or you can do:
$id = Flight::request()->query->id;
```
# HTTP Caching
## HTTP Caching
Flight provides built-in support for HTTP level caching. If the caching condition is met, Flight will return an HTTP `304 Not Modified` response. The next time the client requests the same resource, they will be prompted to use their locally cached version.
## Last-Modified
### Last-Modified
You can use the `lastModified` method and pass in a UNIX timestamp to set the date and time a page was last modified. The client will continue to use their cache until the last modified value is changed.
Keep in mind that calling either `lastModified` or `etag` will both set and check the cache value. If the cache value is the same between requests, Flight will immediately send an `HTTP 304` response and stop processing.
# Stopping
## Stopping
You can stop the framework at any point by calling the `halt` method:
@ -673,11 +673,11 @@ Calling `halt` will discard any response content up to that point. If you want t
Flight::stop();
```
# Framework Methods
## Framework Methods
Flight is designed to be easy to use and understand. The following is the complete set of methods for the framework. It consists of core methods, which are regular static methods, and extensible methods, which can be filtered or overridden.
## Core Methods
### Core Methods
```php
Flight::map($name, $callback) // Creates a custom framework method.
@ -691,7 +691,7 @@ Flight::has($key) // Checks if a variable is set.