Laravel Study Notes (2)

Source: Internet
Author: User
Tags netbeans

Solved the problem of automatic class loading. The remaining problem is reading the documentation. Although the official documentation of laravel is simple, it contains a lot of basic knowledge. To learn about laravel, you 'd better first look at the official documentation, I feel very helpful, because the laravel Framework's source code does not seem easy to use. It is faster to read the documentation. If you want to learn more about it, you can consider studying the source code.

Considering the complexity of the laravel framework, it is recommended that you do not use the editor and use IDE for development, because IDE can debug, jump to class declaration files, and other functions that are automatically completed. However, if you insist on using the editor, sublime is recommended. Common ides include netbeans, phpeclipse, Aptana, zendstudio, and phpstorm. Among them, zendstudio and phpstorm are paid software. If you have money, it is better to choose, if you pay attention to copyright, you can consider netbeans, phpeclipse, Aptana, phpeclipse and Aptana. I prefer netbeans and Aptana, they all provide support in terms of syntaxes, code prompts, debugging, and version management. I chose netbeans because netbeans supports PHP built-in Web servers, it is very convenient to start a new project. It is suitable for beginners. You can also select Aptana, which is only a bit of trouble. You need to modify the Apache configuration file and add a virtual host. Before using IDE, it is best to add ide support, because the common ide cannot understand how laravel facades works (not only does ide understand it, but I do not understand it ), barryvdh has developed an ide-helper tool, and the configuration process is relatively simple. The official website is very detailed. Here is a note: 1) Modify composer. the JSON content is as follows: add "barryvdh/laravel-ide-helper" under require: "1. * "then in the laravel root directory (composer. JSON directory) Run composer update or: Composer require barryvdh/laravel-ide-helper: 1. * After running, a barrayvdh directory is added to the vendor directory. 2) in APP/config/app. add a line to the providers array in PHP: 'barryvdh \ laravelidehelper \ idehelperserviceprovider', 3) now the code prompts are available, but if a new component is added, you must manually run the PHP artisan clear-compiled PHP artisan ide-helper: Generate command to automatically generate each update. modify script-> post-Update-CMD in JSON and add the following "post-Update-cmd": ["php artisan clear-compiled", "php artisan ide-helper: generate "," php artisan optimize "], so that you can use the automatic prompt, and you can take a look at the automatically generated _ ide- Helper. PHP file, you can see the relationship between many classes, such as in routes. in PHP route, according to the _ ide-helper.php, you can know that the route corresponds to \ illuminate \ routing \ router, according to the relationship between the vendor/Composer/autoload_classmap.php file, you can know, the corresponding information is Vendor/laravel/framework/src/illuminate/routing/router. PHP. Netbeans code jump is often also to the _ ide-helper.php file. If you are familiar with PHP, the learning framework will be very simple. If you are not familiar with it, we recommend that you have a PHP reference book for future reference, if you use it frequently, you are advised to buy one.
According to the official documentation, the lifecycle of a request is as follows: 1) The request enters public/index. PHP file. If the Apache server is used, it will read. the htaccess file calls the rewrite function and does not need to input index. PHP, you can call it, but in the case of a virtual directory, you have to write the index. PHP. 2) Call Bootstrap/start. PHP file, create an application (illuminate \ Foundation \ Application) and check the environment. 3) Call framework/start. PHP, path: \ vendor \ laravel \ framework \ SRC \ illuminate \ Foundation \ Start. PHP 4) Load global under the APP/start directory. PHP, artisan. PHP, local. PHP 5) Load APP/routes. PHP 6) send the request object to the application and return the response object after processing. 7) it is complicated to return the response object to the client, note that the above "LOAD" and "call" all mean "require. But we don't need to worry about most of the content. The first thing we need to know is APP/routes. PHP: this is the core function of laravel. It transfers your request to the corresponding resource, such as displaying the PHP file and controller (PHP) file on the page. For developers, note the routes. PHP. This file represents the PHP program that is finally called by each browser. This is actually similar to the Java MVC. I am a little surprised that PHP can do this. It is a good thing, which means it is easier to learn. Routes. common route scheduling methods in PHP Include the following: Get ('/', function () {return view: Make ('hello ');}); it should be noted that the route actually corresponds to vendor/laravel/framework/src/illuminate/routing/router. PHP, where/Represents the virtual path, get represents the request method, or post, or any (any method), view: Make ('hello ') indicates that the route destination is APP/View/hello. PHP, pointing to other files, and so on. Usually when we switch to a new page, we need to carry some objects or arrays in the past, it is also very easy, as long as return view: Make ("hello ")-) with ('user', $ user)-> with ('student ', $ student) on the new page, you only need to call $ user directly, $ student. The preceding routing is the simplest method. If you need more logic computing before arriving at a new page, you need to put the logic into the Controller class, which will make routes. PHP is concise. Of course, if the logic in the Controller class is too complex, you can also split the logic. For example, the business logic is complicated and you can save the business logic in other PHP files, for example, you can create a business directory to save business logic. Remember to add the business directory to the autoload of composer. JSON before it can be automatically loaded and called by other PHP files. All controller classes are sub-classes of basecontroller. The basecontroller is located in the/APP/controller directory. The route call method is as follows: Get ('user/profile ', array ('as' => 'profile ', 'uses' => '[email protected, the showprofile method pointing to the usercontroller class. profile is the route name. You can use this name elsewhere to jump to the showprofile method of usercontroller. Generally, you can develop the SDK by knowing this. For more information, see the official documentation, including the routing and adding parameters, such as user/profile/1 and filter.

Laravel Study Notes (2)

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.