Skip to content

Commit

Permalink
Work on documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 7, 2013
1 parent b53c684 commit 96bd7d9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
20 changes: 18 additions & 2 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Next, we need to instruct the framework how to determine which environment it is

In this example, 'local' is the name of the environment and 'your-machine-name' is the hostname of your server. On Linux and Mac, you may determine your hostname using the `hostname` terminal command.

You may also pass a `Closure` to the `detectEnvironment` method, allowing you to implement your own environment detection:
If you need more flexible environment detection, you may pass a `Closure` to the `detectEnvironment` method, allowing you to implement environment detection however you wish:

$env = $app->detectEnvironment(function()
{
Expand All @@ -71,10 +71,22 @@ You may access the current application environment via the `environment` method:

$environment = App::environment();

You may also pass arguments to the `enviornment` method to check if the environment matches a given value:

if (App::environment('local'))
{
// The environment is local
}

if (App::environment('local', 'staging'))
{
// The environment is either local OR staging...
}

<a name="maintenance-mode"></a>
## Maintenance Mode

When your application is in maintenance mode, a custom view will be displayed for all routes into your application. This makes it easy to "disable" your application while it is updating. A call to the `App::down` method is already present in your `app/start/global.php` file. The response from this method will be sent to users when your application is in maintenance mode.
When your application is in maintenance mode, a custom view will be displayed for all routes into your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. A call to the `App::down` method is already present in your `app/start/global.php` file. The response from this method will be sent to users when your application is in maintenance mode.

To enable maintenance mode, simply execute the `down` Artisan command:

Expand All @@ -90,3 +102,7 @@ To show a custom view when your application is in maintenance mode, you may add
{
return Response::view('maintenance', array(), 503);
});

### Maintenance Mode & Queues

While your application is in maintenance mode, no [queue jobs](/docs/queues) will be handled. The jobs will continue to be handled as normal once the application is out of maintenance mode.
10 changes: 7 additions & 3 deletions controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ If you choose to nest or organize your controller using PHP namespaces, simply u

Route::get('foo', 'Namespace\FooController@method');

> **Note:** Since we're using [Composer](http:https://getcomposer.org) to auto-load our PHP classes, controllers may live anywhere on the file system, as long as composer knows how to load them. The controller directory does not enforce any folder structure for your application. Routing to controllers is entirely de-coupled from the file system.
You may also specify names on controller routes:

Route::get('foo', array('uses' => 'FooController@method',
'as' => 'name'));

To generate a URL to a controller action, you may use the `URL::action` method:
To generate a URL to a controller action, you may use the `URL::action` method or the `action` helper method:

$url = URL::action('FooController@method');

$url = action('FooController@method');

You may access the name of the controller action being run using the `currentRouteAction` method:

$action = Route::currentRouteAction();
Expand Down Expand Up @@ -169,11 +173,11 @@ And, you may also specify a subset of actions to handle on the route:
<a name="handling-missing-methods"></a>
## Handling Missing Methods

A catch-all method may be defined which will be called when no other matching method is found on a given controller. The method should be named `missingMethod`, and receives the parameter array for the request as its only argument:
A catch-all method may be defined which will be called when no other matching method is found on a given controller. The method should be named `missingMethod`, and receives the method and parameter array for the request:

**Defining A Catch-All Method**

public function missingMethod($parameters)
public function missingMethod($method, $parameters)
{
//
}
24 changes: 14 additions & 10 deletions errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<a name="error-detail"></a>
## Error Detail

By default, error detail is enabled for your application. This means that when an error occurs you will be shown an error page with a detailed stack trace and error message. You may turn off error details by setting the `debug` option in your `app/config/app.php` file to `false`. **It is strongly recommended that you turn off error detail in a production environment.**
By default, error detail is enabled for your application. This means that when an error occurs you will be shown an error page with a detailed stack trace and error message. You may turn off error details by setting the `debug` option in your `app/config/app.php` file to `false`.

> **Note:** It is strongly recommended that you turn off error detail in a production environment.
<a name="handling-errors"></a>
## Handling Errors
Expand Down Expand Up @@ -46,25 +48,27 @@ To listen for PHP fatal errors, you may use the `App::fatal` method:

If you have several exception handlers, they should be defined from most generic to most specific. So, for example, a handler that handles all exceptions of type `Exception` should be defined before a custom exception type such as `Illuminate\Encryption\DecryptException`.

### Where To Place Error Handlers

There is no default "home" for error handler registrations. Laravel offers you freedom in this area. One option is to define the handlers in your `start/global.php` file. In general, this is a convenient loation to place any "bootstrapping" code. If that file is getting crowded, you could create an `app/errors.php` file, and `require` that file from your `start/global.php` script. A third option is to create a [service provider](/docs/ioc#service-providers) that registers the handlers. Again, there is no single "correct" answer. Choose a location that you are comfortable with.

<a name="http-exceptions"></a>
## HTTP Exceptions

Exceptions in respect to HTTP, refer to errors that may occur during a client request. This may be a page not found error (404), an unauthorized error (401) or even a generated 500 error. In order to return such a response, use the following:

App::abort(404, 'Page not found');
Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404), an "unauthorized error" (401) or even a developer generated 500 error. In order to return such a response, use the following:

The first argument, is the HTTP status code, with the following being a custom message you'd like to show with the error.
App::abort(404);

In order to raise a 401 Unauthorized exception, just do the following:
Optionally, you may provide a response:

App::abort(401, 'You are not authorized.');
App::abort(403, 'Unauthorized action.');

These exceptions can be executed at any time during the request's lifecycle.
This method may be used at any time during the request's lifecycle.

<a name="handling-404-errors"></a>
## Handling 404 Errors

You may register an error handler that handles all "404 Not Found" errors in your application, allowing you to return custom 404 error pages:
You may register an error handler that handles all "404 Not Found" errors in your application, allowing you to easily return custom 404 error pages:

App::missing(function($exception)
{
Expand All @@ -74,7 +78,7 @@ You may register an error handler that handles all "404 Not Found" errors in you
<a name="logging"></a>
## Logging

The Laravel logging facilities provide a simple layer on top of the powerful [Monolog](http:https://github.com/seldaek/monolog). By default, Laravel is configured to create daily log files for your application, and these files are stored in `app/storage/logs`. You may write information to these logs like so:
The Laravel logging facilities provide a simple layer on top of the powerful [Monolog](http:https://github.com/seldaek/monolog) library. By default, Laravel is configured to create a single log file for your application, and this file is stored in `app/storage/laravel.log`. You may write information to the log like so:

Log::info('This is some useful information.');

Expand Down
8 changes: 7 additions & 1 deletion responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ A `Response` instance inherits from the `Symfony\Component\HttpFoundation\Respon

return $response;

If you need access to the `Response` class methods, but want to return a view as the response content, you may use the `Response::view` method for convenience:

return Response::view('hello')->header('Content-Type', $type);

**Attaching Cookies To Responses**

$cookie = Cookie::make('name', 'value');
Expand All @@ -40,7 +44,7 @@ A `Response` instance inherits from the `Symfony\Component\HttpFoundation\Respon
return Redirect::to('user/login');

**Returning A Redirect With Flash Data**

return Redirect::to('user/login')->with('message', 'Login Failed');

> **Note:** Since the `with` method flashes data to the session, you may retrieve the data using the typical `Session::get` method.
Expand Down Expand Up @@ -187,3 +191,5 @@ View **creators** work almost exactly like view composers; however, they are fir
return Response::download($pathToFile);

return Response::download($pathToFile, $name, $headers);

> **Note:** Symfony HttpFoundation, which manages file downloads, requires the file being downloaded to have an ASCII file name.

0 comments on commit 96bd7d9

Please sign in to comment.