企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
###*路由方法匹配函数* * * * * * ~~~ /** * @param array $method get\post\ajax方法(匹配多); * * @param string $param 匹配单个,将传参以\分割与当前url参数数组匹配 * @param array $param 匹配多个 * * @param string $func 调用对应类对应方法 * @param \Closure $func 调用函数,并传参$args * * @param bool $aiload 是否智能加载需要类文件(默认否,在一个类方法或函数加载类文件过多的时候使用) * * @return void */ Route::get($param, $func, array $args = [], bool $aiload = false) : void; Route::post($param, $func, array $args = [], bool $aiload = false) : void; Route::ajax($param, $func, array $args = [], bool $aiload = false) : void; Route::method(array $method, $param, $func, array $args = [], bool $aiload = false) : void; ~~~ ###*参数匹配* * * * * * 格式: + **string** + **string(string)/value_name(roule)/value_name(roule)** + **string(string)@?get1(roule)&get2(roule)** + **string(string)@#post1(roule)&post1(roule)** + **string(string)@#post1(roule)?get1(roule)** + **string(string)/value_name(roule)/...@?id(roule)&...#name(roule)&...** > 注解 第一个string为定值匹配 之后value_name按照括号中对应路由规则匹配 匹配成功则添置get参数中,名称为value_name,优先级最高,覆盖正常get传参 @之后为get或post参数检测,?接get#接post,&连接,括号中为检测规则 ~~~ //例: Route::get('novel/novel(string)/number(int), 'View@showNovel@?novel&number'); //匹配novel/任意字符串(路由规则string)/任意数字(路由规则int) //www.example.com/novel/ceshixiaoshuo/1 //调用View->showNovel('ceshixiaoshuo',1); ~~~ ###*类函数传参* * * * * * 格式: + **class@method** + **class@method@?get1&get2** + **class@method@#post1&post2** + **class@method[@?get1&get2#post1&post2]** **如果不存在则传值null** ~~~ /** * @example */ Index@index ----> 当前命名空间//Index类index方法 Index@index@?id&name ----> 并传递$_GET['id'],$_GET['name'] Index@index@#id&name ----> 并传递$_POST['id'],$_POST['name'] Index@index@?id#name ----> 并传递$_GET['id'],$_POST['name'] ~~~ ###*方法匹配实例* * * * * * ~~~ /** * @example * 配合路由规则,匹配空字符 * 调用函数... */ Route::get(':empty', function () { code...... }); /** * @example * 匹配index * 调用当前 命名空间//Index类的index方法 */ Route::get('index','Index@index'); /** * @example * 匹配test * 调用当前命名空间//Index类的test方法 */ Route::get('test','Index@test'); /** * @example * 匹配empty * 调用方法 * 传参1 */ Route::get('empty',function(int $number){ echo $number; },[1]); /** * @example * 匹配page/id/:int(路由规则) * 调用当前命名空间//Index类page方法 * 传参$_GET['id'],必定为路径中这个id; */ Route::get('page/id(:int)', 'Index@page@?id'); /** * @example * 匹配edit * 调用当前命名空间//Index类edit方法 * 传参$_POST['test'] */ Route::post('edit', 'Index@edit@#text'); ~~~