Full interpretation of PHP's popular development framework Laravel, comprehensive interpretation of laravel_php tutorial

Source: Internet
Author: User
Tags ruby on rails

Full interpretation of PHP's popular development Framework Laravel, a comprehensive interpretation of laravel


Main technical features of Laravel:

1, Bundle is Laravel expansion package organization form or salutation. Laravel's expansion pack warehouse is quite mature and can easily be used to install expansion packs (bundles) into your application. You can choose to download an expansion pack (bundle) and then copy it to the bundles directory, or install it automatically via the command line tool "Artisan".
2, in Laravel already has a set of advanced PHP ActiveRecord implementation-eloquent ORM. It makes it easy to apply "constraints" to both sides of the relationship, so you have full control over the data and enjoy all the conveniences of ActiveRecord. Eloquent native supports all methods of the query constructor (Query-builder) in fluent.
3. Application logic (application logic) can be implemented either in the controller (controllers) or directly into the route declaration, and the syntax is similar to the Sinatra framework. Laravel's design philosophy is to give developers maximum flexibility to create very small websites and build large enterprise applications.
4. Reverse Routing (Reverse Routing) gives you the ability to create a link (URI) by routing (routes) name. Simply use the route name, Laravel will automatically help you create the correct URI. This way you can change your routing (routes) at any time, and Laravel will automatically update all relevant links for you.
5. RESTful controller (restful Controllers) is an optional way to differentiate between get and post request logic. For example, in a user login logic, you declare a get_login () action to handle the service that gets the landing page, and also declare a post_login () action to verify the data that the form is post, and after verification, Make a decision to re-turn (redirect) to the landing page or to the console.
6. The auto-load class (class auto-loading) simplifies the loading of classes, so that it is not necessary to maintain automatic loading of configuration tables and non-essential component loading work. When you want to load any library or model, use it immediately, and Laravel will automatically load the required files for you.
7. View composers is essentially a piece of code that executes automatically when the view is loaded. The best example is the blog side of the random article recommendation, "View Assembler" contains the logic to load the recommended random article, so that you only need to load the content area of the Views (view) on the line, the other things laravel will help you to do it automatically.
8. The Reverse control container (IoC container) provides a convenient way to generate new objects, instantiate objects at any time, and Access Singleton (singleton) objects. Reverse control (IoC) means that you hardly need to intentionally load external libraries (libraries) to access them anywhere in your code, and you don't have to tolerate cumbersome, redundant code structures.
9. Migration (migrations) is like a version control tool, but it manages the database paradigm and is integrated directly into the laravel. You can use the "Artisan" command-line tool to generate and execute "migration" instructions. When your team member changes the database paradigm, you can easily update the current project through the version Control tool and then execute the "migrate" command, so your database is up-to-date!
10, Unit Test (unit-testing) is a very important part of Laravel. Laravel itself contains hundreds of test cases to ensure that any modification does not affect the functionality of other parts, which is one reason why the industry laravel is considered to be the most stable version. Laravel also provides handy features to make your own code easy to unit test. All test cases can be run with the Artisan command-line tool.
11. The automatic paging (Automatic pagination) feature avoids the mixing of a large number of unrelated paging configuration codes in your business logic. Convenient is not need to remember the current page, as long as the total number of entries from the database, and then use Limit/offset to get the selected data, and finally call the ' paginate ' method, let laravel the page link output to the specified view (views), Laravel will do all the work for you automatically. Laravel's automatic paging system is designed to be easy to implement and easy to modify. Although Laravel can handle these tasks automatically, do not forget to call the appropriate method and manually configure the paging system Oh!

Here are some small examples to explain:
Micro-services and program interfaces
Lumen is a streamlined micro-framework derived from Laravel. Its high-performance program interface allows you to develop micro projects more easily and quickly. Lumen integrates the important features of all laravel with minimal configuration, and you can migrate the complete framework by copying the code into the Laravel project.

<?php$app->get ('/', function () {  return view (' lumen ');}); $app->post (' framework/{id} ', function ($framework) {  $this->dispatch (New Energy ($framework));});

HTTP path
Laravel has a fast, efficient routing system similar to that of Ruby on rails. It allows the user to associate the parts of the application in a way that allows them to enter paths through the browser.

HTTP middleware

Route::get ('/', function () {   return ' Hello World ';});

Applications can be protected by middleware-the middleware handles parsing and filtering HTTP requests on the server. You can install middleware to authenticate registered users and avoid issues such as cross-site scripting (XSS) or other security conditions.

<?php namespace App\http\middleware; Use Closure; Class Oldmiddleware {public  function handle ($request, Closure $next) {   if ($request->input (' age ') <= 200) {      return redirect (' home ');   }   Return $next ($request); }}

Cache
Your application can get a robust cache system that can be adjusted to make the application load faster, which gives your users the best experience.

Cache::extend (' MONGO ', function ($app) {   return cache::repository (new Mongostore);});

Identity verification
Safety is of paramount importance. The laravel comes with authentication to the local user and can use the "remember" option to remember the user. It also lets you for example some extra parameters, such as whether the display is active for the user.

if (auth::attempt ([' email ' + $email, ' password ' + $password, ' active ' = 1], $remember)) {   //the user is Being remembered ...}

Various integration
Laravel cashier can meet all the requirements you need to develop your payment system. In addition, it synchronizes and integrates the user authentication system. So you no longer have to worry about integrating your billing system into your development.

$user = User::find (1), $user->subscription (' monthly ')->create ($creditCardToken);

Task automation
Elixir is a Laravel program interface that allows us to define tasks using gulp, and we can use elixir to define pre-processors that streamline CSS and JavaScript.

Elixir (function (Mix) {   mix.browserify (' main.js ');});


Encryption
A secure application should be able to encrypt the data. With Laravel, you can enable the OpenSSL secure encryption algorithm AES-256-CBC to meet all your needs. In addition, all encrypted values are signed by a verification code that detects whether the encrypted information has been altered.

Use illuminate\contracts\encryption\decryptexception; try {   $decrypted = Crypt::d ecrypt ($encryptedValue);} catch (Decryptexception $e) {   //}

Event handling
The definition, recording, and listening of events in an application are very rapid. The listen in the Eventserviceprovider event contains a list of all the events recorded on your application.

protected $listen = [' app\events\podcastwaspurchased ' = [    ' app\listeners\emailpurchaseconfirmation ',],];

Page out
Paging in Laravel is very easy because it generates a series of links based on the current page of the user's browser.

<?php namespace App\http\controllers; Use DB; Use App\http\controllers\controller; Class Usercontroller extends Controller {public  function index () {   $users = db::table (' users ')->paginate (15 );  Return view (' User.index ', [' users ' and ' = $users]); }}

Object-Relational mapping (ORM)
The laravel contains a layer that processes the database, and its object-relational mappings are called eloquent. The other one also applies to PostgreSQL.

$users = User::where (' votes ', ' > ', '->take ')->get (); foreach ($users as $user) {  var_dump ($user name);}

Unit Test
The development of unit tests is a time-consuming task, but it is the key to ensuring that our applications remain in good working. Unit tests can be performed using PHPUnit in Laravel.

 
  
   
  Visit ('/')->see (' Laravel 5 ')->dontsee (' Rails '); }}
 
  

Todo List
Laravel provides the option to use the to-do list in the background to handle complex, lengthy processes. It allows us to process certain processes asynchronously without requiring the user's continuous navigation.

Queue:: Push (new SendEmail ($ message));


http://www.bkjia.com/PHPjc/1061519.html www.bkjia.com true http://www.bkjia.com/PHPjc/1061519.html techarticle full interpretation of PHP's popular development Framework Laravel, a comprehensive interpretation of the main technical features of Laravel Laravel: 1, bundle is the Laravel expansion package organization form or salutation. Laravel's expansion pack Warehouse has ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.