当前位置:网站首页>Controller in laravel framework
Controller in laravel framework
2022-07-05 13:49:00 【Weichi Begonia】
1. How to create a controller
stay app/Http/Controllers Under the folder , New name is MemberController.php The file of , And add namespace , as follows :
<?php
namespace App\Http\Controllers;
The new class , And define functions :( Be careful : The class name of the controller must be consistent with the file name , Class names are capitalized )
class MemberController extends Controller
{
public function info($id){
return $id."_".'member-info';
}
}
2. laravel How are routes and controllers associated in
//match Method Route::match(['get', 'post'], 'member/{id}', "[email protected]")->where(['id'=>'\d+']);
such as , I want to set up a route , And above MemberController.php In the document info Function correlation , It can be defined as follows :
// Pass in the parameter
Route::get('member/{id}', "[email protected]")->where(['id'=>'\d+']);
where Function can set some restrictions on parameters
3. After controller Association , How to use the routing feature ?- How to use any/match/group/ Route alias and other methods ?
//any Method
Route::any('member/{id}', "[email protected]")->where(['id'=>'\d+']);
//match Method
Route::match(['get', 'post'], 'member/{id}', "[email protected]")->where(['id'=>'\d+']);
// Routing alias , Note the direction controller when key by uses
Route::get('member/info/{id}', ["as"=>"member", "uses"=>"[email protected]"]);
// routing group
Route::group(["prefix"=>"member"], function(){
Route::get('info/{id}', "[email protected]");
});
边栏推荐
- 真正的缓存之王,Google Guava 只是弟弟
- Selenium crawls Baidu pictures
- With 4 years of working experience, you can't tell five ways of communication between multithreads. Dare you believe it?
- js 从一个数组对象中取key 和value组成一个新的对象
- Laravel generate entity
- RK3566添加LED
- Address book (linked list implementation)
- Elfk deployment
- When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
- 锚点导航小demo
猜你喜欢
[server data recovery] a case of RAID5 data recovery stored in a brand of server
PHP basic syntax
Win10——轻量级小工具
[South China University of technology] information sharing of postgraduate entrance examination and re examination
Usage, installation and use of TortoiseSVN
Scientific running robot pancakeswap clip robot latest detailed tutorial
南理工在线交流群
Huawei push service content, read notes
Godson 2nd generation burn PMON and reload system
研究生可以不用学英语?只要考研英语或六级分数高!
随机推荐
The real king of caching, Google guava is just a brother
【 script secret pour l'utilisation de MySQL 】 un jeu en ligne sur l'heure et le type de date de MySQL et les fonctions d'exploitation connexes (3)
Aspx simple user login
With 4 years of working experience, you can't tell five ways of communication between multithreads. Dare you believe it?
Attack and defense world crypto WP
Redis6 data type and operation summary
Integer = = the comparison will unpack automatically. This variable cannot be assigned empty
Solution to the prompt of could not close zip file during phpword use
Simple PHP paging implementation
网络安全-HSRP协议
Log4j utilization correlation
"Baidu Cup" CTF competition in September, web:upload
Binder communication process and servicemanager creation process
Jetpack Compose入门到精通
Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
Godson 2nd generation burn PMON and reload system
[public class preview]: basis and practice of video quality evaluation
Pancake Bulldog robot V2 (code optimized)
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution