2.控制器 php artisan make:controller 控制器名 (大驼峰)+Controller
1.控制器生成:
php artisan make:controller TestController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;//命名空间的三元素:常量,方法和类
class TestController extends Controller
{
public function test1(){
phpinfo();
}
}
2.控制器路由:
使用路由规则调用控制器下的方法,非回调函数
“控制器类名@方法名”
// 实战测试
Route::get('/home/test/test1','TestController@test1');
http://www.laravel02.com/home/test/test1
3. 分目录管理, 命令里增加目录名即可:
E:\phpStudy\PHPTutorial\WWW\laravel02>php artisan make:controller Home/IndexController
E:\phpStudy\PHPTutorial\WWW\laravel02>php artisan make:controller Admin/IndexController
//home目录 index 类的index方法
Route::get('/home/index/index','Home\IndexController@index');
Route::get('/admin/index/index','Admin\IndexController@index');
http://www.laravel02.com/home/index/index
http://www.laravel02.com/admin/index/index
4. 接收用户输入
接收用户输入的类:Illuminate\Support\Facades\Input
Facades 是类的一个接口实现,算静态方法
Input::get();
Input::all();
input::only([])
input::except([])
简化 use Illuminate\Support\Facades\Input ,给它添加别名
测试:
Route::get('/home/test/test2','TestController@test2');
http://www.laravel02.com/home/test/test2?ddd=aaaa&id=112&name=zhangsan
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;//命名空间的三元素:常量,方法和类
//use Illuminate\Support\Facades\Input;
use Input;
class TestController extends Controller
{
public function test1(){
phpinfo();
}
//测试input
public function test2(){
//获取一个值,如果没值默认第二个参数
echo Input::get('id',"10086");
//获取全部(数组格式)
$all = Input::all();
//dump + die ,后续代码不会执行
// dd($all);
//获取指定信息(字符串格式)
// dd(Input::get('name'));
//获取指定几个key(数组格式)
// dd(Input::only(['id','name']));
//获取指定几个key之外的值(数组格式)
// dd(Input::except(['name']));
//判断key是否存在(boole)
dd(Input::has('name'));
}
}
输出:
112
array:1 [▼
"id" => "112"
]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
2014-09-25 Telepro工具注册码
2013-09-25 Warning: Cannot modify header information - headers already sent by ... functions_general.php on line 45