企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ### 组件说明 > Lying的Dispatch是内置组件,用于执行控制器的方法。 ### 配置选项 | 配置名 | 参数类型 | 可选 | 默认值 | 说明 | | --- | --- | --- | --- | --- | | class | string | 是 | lying\service\Dispatch | 不可更改 | ### 示例配置 Dispatch组件暂时不需要配置,可直接使用 ### 调用方式 ~~~php \Lying::$maker->get('dispatch'); \Lying::$maker->dispatch(); \Lying::$maker->dispatch; ~~~ ### 方法列表 ~~~php /** * 程序执行入口 * @param array|string $route 要调度的路由 * @param array $params 传控方法的参数,若果放空则自动从GET参数获取 * @return mixed 返回执行结果 * @throws InvalidRouteException 路由无法解析抛出异常 * @throws HttpException 缺少参数抛出异常 * @throws \ReflectionException 反射类异常 * @throws \Exception 控制器未继承基础控制器抛出异常 */ public function run($route, array $params = []); ~~~ ### 使用示例 > 由于有了调度器,所以在任何地方都可以执行任意一个控制器的方法 ~~~php //调用index模块,user控制器的info方法 $result = Lying::$maker->dispatch->run('index/user/info', ['username'=>'lying']); ~~~