display()" method to render templates, while Laravel uses the "return view()" method; 2. Laravel is a rerouting framework, and thinkphp requires a controller method for normal access."/> display()" method to render templates, while Laravel uses the "return view()" method; 2. Laravel is a rerouting framework, and thinkphp requires a controller method for normal access.">

Home >PHP Framework >ThinkPHP >Are thinkphp and laravel the same?

Are thinkphp and laravel the same?

WBOY
WBOYOriginal
2022-06-16 17:37:163907browse

thinkphp and laravel are different. Although thinkphp and laravel are both PHP development frameworks, they have many differences: 1. The methods of rendering the last shift are different. Thinkphp uses the "$this->display()" method to render templates, while Laravel uses the "return view()" method. ; 2. Laravel is a rerouting framework, and thinkphp requires a controller method for normal access.

Are thinkphp and laravel the same?

The operating environment of this article: Windows 10 system, ThinkPHP5&&Laravel8 version, Dell G3 computer.

Is thinkphp the same as laravel

Thinkphp is different from laravel

ThinkPHP is free and open source, fast, simple, object-oriented and light A massive PHP development framework, ThinkPHP can support server environments such as windows/Unix/Linux. The official version requires PHP5.0 or above, supports MySql, PgSQL, Sqlite databases and PDO extensions. The ThinkPHP framework itself has no special module requirements. The specific application system operating environment requirements depend on the modules involved in development.

Laravel is a free and open source PHP Web framework created by Taylor Otwell, designed to implement the MVC architecture of Web software and serve as an alternative to CodeIgniter. Its source code is hosted on GitHub, and the license terms are MIT license. Features of Laravel include: supporting user authentication and permissions, having a modular package system with its own package library, providing ways to connect to many types of relational databases, providing tools to assist with application deployment and maintenance, and developing Lots of syntactic sugar.

Main differences: (thinkPHP is more suitable for Chinese coding habits):

1. Differences in rendering template methods:

In the Laravel framework, Use return view() to render the template;

And ThinkPHP uses $this->display() to render the template;

2. In the Laravel framework, due to its considerations It's cross-site request forgery, so if you use the form form to pass values ​​in the post method, if you don't add {{csrf_field()}} to the form form, a syntax error of TokenMethodnotfound will be reported;

And TP The framework needs to manually complete the code to prevent cross-site attacks;

3. Laravel is a re-routing framework (5.4). All functions are initiated by routing. Even if there is no controller method, just write You can access it by routing, thinkPHP (3.2), you must have a controller method for normal access;

4. Laravel has powerful community extensions (composer extension is automatically loaded);

5. Laravel has a powerful Blade template engine;

6. Middleware, Laravel features, can realize processing before and after access, such as request and return, permission authentication, etc.;

7. Conditional judgment Differences in the way statements are written:

The if else judgment statement and the foreach statement in the Laravel framework must start with @if and end with @endif. If not, a syntax error will be reported. Same goes for @foreach @endforeach;

The TP framework is used in the same way as PHP syntax rules, direct ifesle statement judgment and foreach loop traversal

Laravel has a large number of built-in methods for developers to use, which in actual applications is closer to "let The development idea of ​​​​"object does everything", for example, during background form verification, Laravel has a large number of built-in verification methods, such as verification of username: we use 'username'=>'required' (cannot be empty) in the validate method )|alpha_dash (must have numbers, letters and underlines)|between:6,18 (how many digits are between); also built-in a large number of methods such as email; same: field name; diff: field name, etc., which greatly improves the development speed. ;

Encryption method In the TP framework, we use md5(); when encrypting usernames and passwords. However, the disadvantage of md5 is that it can be reversed and cracked, and the same password md5 under the same rules The encrypted strings may appear the same, which reduces their security;

However, the "Hash" Hash encryption one-way encryption method is built into the Laravel framework, and the same parameters are encrypted. Strings will never appear in the same situation, which improves security;

In actual development, we often encounter such a problem, that is, the development location is not fixed, which causes us to need frequent changes Database configuration has caused trouble for development work. TP still has not avoided this "disaster"; in the laravel framework, the emergence of .env environment files solves this trouble. We only need to configure the .env files in different work locations. Configure again, because whether it is git or svn ".env will not be submitted to the server along with the file."

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Are thinkphp and laravel the same?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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