PHP Framework laravel Two tips, laravel tips two
Using Laravel as a framework for PHP development has been a long time, but there are some official documents that are not covered and are forgotten every once in a while. Recently did a little bit of tidying up, by the way note down memo.
1. Route::controller Route naming:
Using Route::controller can reduce a lot of work in routing customizations, but sometimes you need to name a particular route for use, but the Route::controller method is to specify the route for all the methods in a controller in bulk, how do you name it? You can use the third parameter in the controller ($uri, $controller, $names = Array ()), which is an array, the key of the array is the method, and the value of the array is named.
Copy the Code code as follows:
The signature of the function:
Public Function controller ($uri, $controller, $names = Array ())
Not named general use:
Route::controller (' admin ', ' admincontroller ');
You need to name some of these methods:
Route::controller (' admin ', ' Admincontroller ', Array (
' GetIndex ' = ' admin.index ',
' GetLogin ' = ' admin.login ',
' Postlogin ' = ' admin.login '
));
2. Judging the current operating environment according to system variables
The system defaults to determine whether the local environment method is based on the ' local ' array to specify a set as the host name of the locale, such as on the Office machine, MacBook to do development, you have to write two host names in, I think this is very troublesome. Changed to be judged according to $_server[' laravel_env '), so that I can define the ' laravel_env ' environment variable in all the development machines, the value is ' local ', so the development machine will be automatically recognized as ' local ' environment, and the other case is ' Production '.
Copy the Code code as follows:
The default is to determine whether the local environment is based on the host name
$env = $app->detectenvironment (Array (
' Local ' = = Array (' Homestead ');
));
Modify to determine whether the system variable is specified, not to determine the host name
$env = $app->detectenvironment (function () {
$_env = getenv (' laravel_env ')? getenv (' laravel_env '): Array (
' Local ' = = Array (' Homestead ')
);
return $_env;
});
This is actually going to read the value of $_server[' laravel_env ']
In Apache, you can use the SETENV setting,
In Nginx, you can set it with Fastcgi_param
http://www.bkjia.com/PHPjc/955979.html www.bkjia.com true http://www.bkjia.com/PHPjc/955979.html techarticle PHP Framework Laravel The small tricks of the two, Laravel small tricks with Laravel as a PHP development framework for a long time, but some official documents are not covered in the place, every once in a while ...