企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
系统为一些常用的操作方法封装了助手函数,便于使用,包含如下: | 助手函数 | 描述 | | --- | --- | | abort | 中断执行并发送HTTP状态码 | | app | 快速获取容器中的实例 支持依赖注入 | | bind | 快速绑定对象实例 | | cache | 缓存管理 | | class\_basename | 获取类名(不包含命名空间) | | class\_uses\_recursive | 获取一个类里所有用到的trait | | config | 获取和设置配置参数 | | cookie | Cookie管理 | | download | 获取\\think\\response\\Download对象实例 | | dump | 浏览器友好的变量输出 | | env | 获取环境变量 | | event | 触发事件 | | halt | 变量调试输出并中断执行 | | input | 获取输入数据 支持默认值和过滤 | | invoke | 调用反射执行callable 支持依赖注入 | | json | JSON数据输出 | | jsonp | JSONP数据输出 | | lang | 获取语言变量值 | | parse\_name | 字符串命名风格转换 | | redirect | 重定向输出 | | request | 获取当前Request对象 | | response | 实例化Response对象 | | session | Session管理 | | token | 生成表单令牌输出 | | trace | 记录日志信息 | | trait\_uses\_recursive | 获取一个trait里所有引用到的trait | | url | Url生成 | | validate | 实例化验证器 | | view | 渲染模板输出 | | display | 渲染内容输出 | | xml | XML数据输出 | | app\_path | 当前应用目录 | | base\_path | 应用基础目录 | | config\_path | 应用配置目录 | | public\_path | web根目录 | | root\_path | 应用根目录 | | runtime\_path | 应用运行时目录 | vendor\topthink\framework\src\helper.php ``` //中断执行并发送HTTP状态码 abort($code, string $message = '', array $header = []) //快速获取容器中的实例 支持依赖注入 app(string $name = '', array $args = [], bool $newInstance = false):object|App //快速绑定对象实例 bind($abstract, $concrete = null):Container //缓存管理 cache(string $name = null, $value = '', $options = null, $tag = null):mixed //获取和设置配置参数 config($name = '', $value = null):mixed //Cookie管理 cookie(string $name, $value = '', $option = null):mixed //获取\\think\\response\\Download对象实例 download(string $filename, string $name = '', bool $content = false, int $expire = 180):\think\response\File //浏览器友好的变量输出 dump(...$vars):void //获取环境变量 env(string $name = null, $default = null):mixed //触发事件 event($event, $args = null):mixed //变量调试输出并中断执行 在tp中替代die和exit halt(...$vars) //获取输入数据 支持默认值和过滤 input(string $key = '', $default = null, $filter = ''):mixed //调用反射执行callable 支持依赖注入 invoke($call, array $args = []):mixed //JSON数据输出 json($data = [], $code = 200, $header = [], $options = []): Json //JSONP数据输出 jsonp($data = [], $code = 200, $header = [], $options = []): Jsonp //获取语言变量值 lang(string $name, array $vars = [], string $lang = ''):mixed //字符串命名风格转换 parse_name(string $name, int $type = 0, bool $ucfirst = true): string //重定向输出 redirect(string $url = '', int $code = 302): \think\response\Redirect //获取当前Request对象 request(): \think\Request //实例化Response对象 response($data = '', $code = 200, $header = [], $type = 'html'): Response //Session管理 session($name = '', $value = ''):mixed //生成表单令牌输出 token(string $name = '__token__', string $type = 'md5'): string //生成令牌隐藏表单 token_field(string $name = '__token__', string $type = 'md5'): string //生成令牌meta token_meta(string $name = '__token__', string $type = 'md5'): string //记录日志信息 trace($log = '[think]', string $level = 'log') //Url生成 url(string $url = '', array $vars = [], $suffix = true, $domain = false): UrlBuild //实例化验证器 validate($validate = '', array $message = [], bool $batch = false, bool $failException = true): Validate //渲染模板输出 view(string $template = '', $vars = [], $code = 200, $filter = null): View //渲染内容输出 display(string $content, $vars = [], $code = 200, $filter = null): View //XML数据输出 xml($data = [], $code = 200, $header = [], $options = []): Xml //当前应用目录 app_path($path = ''):string //应用基础目录 base_path($path = ''):string //应用配置目录 config_path($path = ''):string 获取应用配置目录 //web根目录 public_path($path = ''):string //应用运行时目录 runtime_path($path = ''):string //应用根目录 root_path($path = ''):string ``` vendor\topthink\think-helper\src\helper.php ``` //按条件抛异常 throw_if($condition, $exception, ...$parameters):mixed //按条件抛异常 throw_unless($condition, $exception, ...$parameters):mixed //对一个值调用给定的闭包,然后返回该值 tap($value, $callback = null):mixed //返回给定值的默认值。 value($value):mixed //Create a collection from the given value. collect($value = null):Collection //Fill in data where it's missing. data_fill(&$target, $key, $value):mixed //Get an item from an array or object using "dot" notation. data_get($target, $key, $default = null):mixed //Set an item on an array or object using dot notation. data_set(&$target, $key, $value, $overwrite = true):mixed //获取一个trait里所有引用到的trait trait_uses_recursive(string $trait): array //获取类名(不包含命名空间) class_basename($class): string //取一个类里所有用到的trait,包括父类的 class_uses_recursive($class): array ``` > 可以在应用的公共函数文件中重写上面这些助手函数。