变长参数
$a = function (...$vars) {
foreach ($vars as $var) {
dump($var);
}
};
$a(1, 2,3);
tp5跨域
新建
class CronRun
{
public function run(&$dispatch){
$host_name = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : "*";
$headers = [
"Access-Control-Allow-Origin" => $host_name,
"Access-Control-Allow-Credentials" => 'true',
"Access-Control-Allow-Headers" => "x-token,x-uid,x-token-check,x-requested-with,content-type,Host",
"Access-Control-Allow-Credentials" => 'true',
];
if($dispatch instanceof Response) {
$dispatch->header($headers);
} else if($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$dispatch['type'] = 'response';
$response = new Response('', 200, $headers);
$dispatch['response'] = $response;
}
}
}
在 tags.php添加
// 应用行为扩展定义文件
return [
// 应用初始化
'app_init' => ['app\\index\\controller\\CronRun'],
// 应用开始
'app_begin' => [],
// 模块初始化
'module_init' => [],
// 操作开始执行
'action_begin' => [],
// 视图内容过滤
'view_filter' => [],
// 日志写入
'log_write' => [],
// 应用结束
'app_end' => ['app\\index\\controller\\CronRun'],
];