Home > Backend Development > PHP Tutorial > Comprehensive interpretation of PHP's popular development framework Laravel, comprehensive interpretation of laravel_PHP tutorial

Comprehensive interpretation of PHP's popular development framework Laravel, comprehensive interpretation of laravel_PHP tutorial

WBOY
Release: 2016-07-12 09:07:20
Original
899 people have browsed it

Comprehensive interpretation of PHP’s popular development framework Laravel, comprehensive interpretation of laravel

Laravel’s main technical features:

1. Bundle is the organization form or name of Laravel’s expansion package. Laravel's extension package repository is quite mature and can easily help you install extension packages (bundles) into your application. You can choose to download an extension package (bundle) and copy it to the bundles directory, or install it automatically through the command line tool "Artisan".
2. Laravel already has an advanced PHP ActiveRecord implementation -- Eloquent ORM. It can easily apply "constraints" to both sides of the relationship, so that you have complete control over the data and enjoy all the conveniences of ActiveRecord. Eloquent natively supports all methods of the query builder (query-builder) in Fluent.
3. Application logic can be implemented in controllers or directly integrated into route statements, and the syntax is similar to the Sinatra framework. Laravel's design philosophy is to give developers maximum flexibility, allowing them to create very small websites and build large-scale enterprise applications.
4. Reverse Routing gives you the ability to create links (URIs) through route names. Just use the route name and Laravel will automatically create the correct URI for you. This way you can change your routes at any time, and Laravel will automatically update all related links for you.
5. Restful Controllers are an optional way to distinguish GET and POST request logic. For example, in a user login logic, you declare a get_login() action to process the service of obtaining the login page; you also declare a post_login() action to verify the data POSTed from the form, and After validation, a decision is made to redirect to the login page or to the console.
6. Class Auto-loading simplifies the loading of classes. In the future, you no longer need to maintain the auto-loading configuration table and unnecessary component loading. When you want to load any library or model, just use it immediately, and Laravel will automatically load the required files for you.
7. View Composers are essentially a piece of code that is automatically executed when the View is loaded. The best example is the random article recommendation on the side of the blog. The "view assembler" contains the logic for loading the random article recommendation. In this way, you only need to load the view of the content area, and Laravel will do the other things. Complete it automatically for you.
8. The reverse control container (IoC container) provides a convenient way to generate new objects, instantiate objects at any time, and access singleton objects. Inverse control (IoC) means that you almost don't need to load external libraries (libraries), you can access these objects anywhere in the code, and you don't need to endure complicated and redundant code structures.
9. Migrations is like a version control tool, but it manages the database paradigm and is directly integrated into Laravel. You can use the "Artisan" command line tool to generate and execute "migration" instructions. When your team members change the database paradigm, you can easily update the current project through the version control tool, and then execute the "migrate" command. Well, your database is already up to date!
10. Unit-Testing is a very important part of Laravel. Laravel itself contains hundreds of test cases to ensure that any modification will not affect the functionality of other parts. This is one of the reasons why Laravel is considered the most stable version in the industry. Laravel also provides convenient functions to make unit testing your own code easy. All test cases can be run through the Artisan command line tool.
11. The Automatic Pagination function avoids mixing a large amount of irrelevant paging configuration code into your business logic. The convenience is that you don't need to remember the current page, just get the total number of entries from the database, then use limit/offset to get the selected data, and finally call the 'paginate' method to let Laravel output the links of each page to the specified view ( View), Laravel will automatically complete all the work for you. Laravel's automatic paging system is designed to be easy to implement and easy to modify. Although Laravel can handle these tasks automatically, don't forget to call the corresponding methods and manually configure the paging system!

Let’s use some small examples to explain:
Microservices and programming interfaces
Lumen is a micro-framework derived from laravel that focuses on simplicity. Its high-performance programming interface allows you to develop micro-projects more easily and quickly. Lumen integrates all the important features of laravel with minimal configuration. You can migrate the complete framework by copying the code to the laravel project.

<&#63;php
$app->get('/', function() {
  return view('lumen');
});
$app->post('framework/{id}', function($framework) {
  $this->dispatch(new Energy($framework));
});
Copy after login

HTTP path
Laravel has a fast and efficient routing system similar to Ruby on Rails. It allows users to relate parts of an application by typing paths into the browser.

HTTP middleware

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

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

<&#63;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);
 }
}
Copy after login

Caching
Your application can get a robust caching system, which can be adjusted to make the application load faster, which can provide the best experience for your users.

Cache::extend('mongo', function($app) { 
  return Cache::repository(new MongoStore);
});
Copy after login

Identity Verification
Safety is paramount. Laravel comes with local user authentication and can use the "remember" option to remember users. It also allows you to set some additional parameters, such as showing whether the user is active.

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1 ], $remember)) { 
  // The user is being remembered... 
}
Copy after login

Various integrations
Laravel Cashier can meet all the needs you need to develop a payment system. In addition to this, it synchronizes and integrates user authentication systems. So, you no longer need to worry about integrating your billing system into your development.

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

Task Automation
Elixir is a Laravel programming interface that allows us to define tasks using Gulp. We can use Elixir to define preprocessors that can streamline CSS and JavaScript.

elixir(function(mix) { 
  mix.browserify('main.js');
 });
Copy after login


Encryption
A secure application should be able to encrypt data. Using Laravel, you can enable the OpenSSL security 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 changed.

use Illuminate\Contracts\Encryption\DecryptException; 
try { 
  $decrypted = Crypt::decrypt($encryptedValue);
} catch (DecryptException $e) { 
  // 
}
Copy after login

Event handling
Events are defined, recorded and listened to in the application very quickly. The listen in the EventServiceProvider event contains a list of all events recorded on your application.

protected $listen = [
 'App\Events\PodcastWasPurchased' => [ 
   'App\Listeners\EmailPurchaseConfirmation',
 ],
];
Copy after login

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

<&#63;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' => $users]);
 }
}
Copy after login

Object Relational Mapping (ORM)
Laravel includes a layer that handles databases, and its object-relational mapping is called Eloquent. In addition, this also applies to PostgreSQL.

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

Unit testing
The development of unit tests is a time-consuming task, but it is key to ensuring that our applications continue to work properly. PHPUnit can be used to perform unit testing in Laravel.

<php 
use Illuminate\Foundation\Testing\WithoutMiddleware; 
use Illuminate\Foundation\Testing\DatabaseTransactions; 
class ExampleTest extends TestCase { 
 public function testBasicExample() { 
  $this->visit('/')->see('Laravel 5')->dontSee('Rails');
 }
}
Copy after login

To-do list
Laravel offers the option of using a to-do list in the background to handle complex, lengthy processes. It allows us to handle certain processes asynchronously without requiring continuous navigation from the user.

Queue :: push ( new SendEmail ( $ message ));
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1061519.htmlTechArticleComprehensive interpretation of PHP’s popular development framework Laravel, and a comprehensive interpretation of laravel Laravel’s main technical features: 1. Bundle is Laravel’s The organizational form or title of the extension package. Laravel's expansion pack repository has been...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template