当前位置:网站首页>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]");
});
边栏推荐
- 【MySQL 使用秘籍】一网打尽 MySQL 时间和日期类型与相关操作函数(三)
- kafaka 日志收集
- Network security - Novice introduction
- Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
- Network security HSRP protocol
- Data Lake (VII): Iceberg concept and review what is a data Lake
- [public class preview]: basis and practice of video quality evaluation
- Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
- 链表(简单)
- How to apply the updated fluent 3.0 to applet development
猜你喜欢
RK3566添加LED
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
不知道这4种缓存模式,敢说懂缓存吗?
荐号 | 有趣的人都在看什么?
Data Lake (VII): Iceberg concept and review what is a data Lake
Elfk deployment
Win10——轻量级小工具
南理工在线交流群
Embedded software architecture design - message interaction
随机推荐
Log4j utilization correlation
redis6主从复制及集群
【公开课预告】:视频质量评价基础与实践
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
leetcode 10. Regular expression matching regular expression matching (difficult)
Matlab paper chart standard format output (dry goods)
[public class preview]: basis and practice of video quality evaluation
Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
Wechat app payment callback processing method PHP logging method, notes. 2020/5/26
ZABBIX monitoring
asp. Net read TXT file
【MySQL 使用秘籍】一網打盡 MySQL 時間和日期類型與相關操作函數(三)
Godson 2nd generation burn PMON and reload system
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
【华南理工大学】考研初试复试资料分享
Source code analysis of etcd database -- peer RT of inter cluster network layer client
Jetpack Compose入门到精通
jasypt配置文件加密|快速入门|实战
Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"