Home >Development Tools >composer >Teach you to use composer to implement route loading
The following tutorial column of composer will introduce to you how to use composer to implement route loading. I hope it will be helpful to friends in need!
## See the sample code for this tutorial at https:/ /github.com/johnlui/My-First-Framework-based-on-ComposerThe prestigious CodeIgniter framework is the introductory framework for PHP development for many people. It is also the starting point for me to learn how to build a website from scratch. s frame. I learned a lot in CI, among which the in-depth understanding of MVC and the understanding of the nature of the framework had the greatest impact on me. From the perspective of using frameworks to improve development efficiency, the essence of frameworks is routing.
Recommend https://github.com/NoahBuscher/Macaw, the corresponding Composer package is noahbuscher/macaw.Let’s start installing it and change composer.json:
"require": { "noahbuscher/macaw": "dev-master" },Run composer install and get the following directory after success At this point, the Macaw package is installed successfully! The following is the moment to witness the miracle! We will give MFFC life and make it really run! 1: Create a new App/config folder and create a new routs.php file in it with the following content:
This function accepts two parameters,
__callstatic() 做的事情也很简单,分别将目标URL(即 /fuck)、HTTP方法(即 GET)和回调代码压入
路由文件最后一行的 Macaw::dispatch(); 方法才是真正处理当前 URL 的地方。能直接匹配到的会直接调用回调,不能直接匹配到的将利用正则进行匹配。
The above is the detailed content of Teach you to use composer to implement route loading. For more information, please follow other related articles on the PHP Chinese website!