In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the difference between thinkphp and laravel? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Differences: 1. Laravel uses "return view ()" to render templates; ThinkPHP uses "$this- > display ()" to render templates. 2. Different points should be paid attention to in passing values of post. 3. The difference in the writing style of conditional judgment sentences. 4. Different encryption methods. 5. The table is built in different ways.
The operating environment of this tutorial: windows7 system, Laravel6 version, Dell G3 computer.
Main differences: (thinkPHP is more suitable for Chinese coding habits)
1. Different ways of rendering templates
In the Laravel framework, return view () is used to render templates; in ThinkPHP, $this- > display () is used to render templates.
2. Pay attention to different points in the value passed by post.
In the Laravel framework, because it takes cross-site attacks into account, if you use the form form to post the value, if you do not add {{csrf_field ()}} to the form form, the syntax error of TokenMethodnotfound will be reported, while the TP framework needs to manually complete the code to prevent cross-site attacks.
3. The difference in the writing style of conditional judgment sentences.
The if else judgment statement and foreach statement in the Laravel framework must start with @ if and end with @ endif. If not, report a syntax error. @ foreach @ endforeach is the same.
On the other hand, the TP framework is consistent with the use of PHP grammar rules, directly judging by if esle statements and traversing in foreach loops.
4. Encryption method
In the TP framework, we use md5 (); to encrypt usernames and passwords. But the disadvantage of md5 is that it can be cracked in reverse, and under the same rules, the string encrypted by the same password md5 is likely to be the same, which reduces its security. However, the "hash" Hash encryption one-way encryption method is built into the Laravel framework, and the string encrypted by the same parameter will never be the same, which improves the security.
5. Build a table
Laravel has its own independent built-in structure in building tables in the database, so it is completely unnecessary to use native SQL statements or table-building tools such as SQLyogEnt and Navicat to build the database, add, delete, modify, query and exchange data. I think this may be a bright spot that firmly occupies NO.1, but in ThinkPHP, we need to use SQL statements or table-building tools to gradually improve the data.
First, we need to build a model: I use gitbash. Gitbash is a command tool under Windows, based on msys GNU environment, there are git distributed version control tools, mainly used in git. But it can also be used directly in Laravel: php artisan make:model Models/GoodsModel-m to complete the creation of the model and table structure (/ database/migrations).
Fill the goods data table with data. Note that the types of data are strictly differentiated and must be added. After adding, use the php artisan migrate command to complete the creation of the table.
Schema::create ('goods', function (Blueprint $table) {$table- > increments (' id')-> comment ('commodity primary key'); $table- > string ('title')-> comment (' commodity title')
8.3. What if a field does not meet the requirements or needs to be added? Don't worry. After pull the project from github, modify it directly in the data table. Just use:
Php artisan migrate:refresh
6. Laravel is a rerouting framework, all functions are initiated by routing, even if there is no controller method, as long as you write a route, you can access it. ThinkPHP (3.2), you must have a controller method to access it normally.
7. Laravel has a powerful community extension, (composer extension loads automatically)
9. Laravel has a powerful Blade template engine
9. Middleware, Laravel features, which can realize the processing before and after access, such as request and return, authority authentication, etc.
After reading the above, have you mastered the difference between thinkphp and laravel? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.