<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
Route::get('think', function () {
return 'hello,ThinkPHP5!';
});
Route::get('hello/:name', 'index/hello');
return [
];
路由如上:
控制器如下:
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
这个控制器函数,变量name可以不传,但是官方示例路由不是可选参数,还得看一下文档啊,可选参数应该路由中:
Route::get('hello/[:name]', 'index/hello');
最佳答案