TP framework:
ThinkPHP is simple, fast, based on MVC and object-oriented, easy to use, and is a simple and practical Lightweight framework.
Laravel Framework:
Lavavel has always adhered to the principle of elegance, supported composer well, implemented richer extensions, and has active community documentation. Compared with TP, Lavavel is larger and more secure, and is more suitable for developing large and medium-sized projects. It is called the "master development framework".
The difference between TP framework and Laravel framework:
1. How to submit data
Laravel needs to add {csrf_field to the form when submitting the form } to prevent cross-domain attacks, while TP does not.
2. Routing
Laravel must be defined first before using it. The routing file is routes.php; after TP turns on routing in the configuration file, the routing format is: 'Routing expression' => ; 'Routing address and parameters' (the prerequisite for using routing is that the URL supports phthinfo and routing is turned on). Routing can make the URL more in line with SEO.
3. Rendering template method
In the Laravel framework, return view() is used to render the template; while in ThinkPHP, the $this->display() method is used to render the template.
4. How to operate the database
You can use instantiation (create the corresponding model class) and DB:table('table name') to operate the database. It is not easy to use native queries. Similarly, Laravel uses Db::operation ('native sql'), and TP uses Db::query ('native sql').
5. How to write conditional judgment statements
If else judgment statements and foreach statements in the Laravel framework must start with @if and end with @endif. If not, a syntax error will be reported, @foreach @endforeach Same thing.
The TP framework is used in the same way as PHP syntax rules, direct ifesle statement judgment and foreach loop traversal
6. Middleware, Laravel features, can realize processing before and after access, such as request and return , permission authentication, etc.;
7. Laravel upgrade is very simple, but the upgrade of TP large version requires refactoring the code.
The above is the detailed content of What is the difference between TP framework and Laravel framework?. For more information, please follow other related articles on the PHP Chinese website!