🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 其他助手函数 #### [](https://octobercms.com/docs/services/helpers#method-asset)`asset()` 使用当前请求方案(HTTP或HTTPS)生成资产的URL: ~~~ $url = asset('img/photo.jpg'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-config)`config()` 该`config`函数获取配置变量的值。可以使用“点”语法访问配置值,该语法包括文件名和您希望访问的选项。如果配置选项不存在,则可以指定默认值并返回: ~~~ $value = config('app.timezone'); $value = config('app.timezone', $default); ~~~ 的`config`辅助,也可以通过使键/值对的阵列用于设置配置变量在运行时: ~~~ config(['app.debug' => true]); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-dd)`dd()` 该`dd`函数转储给定的变量并结束脚本的执行: ~~~ dd($value); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-env)`env()` 该`env`函数获取环境变量的值或返回默认值: ~~~ $env = env('APP_ENV'); // Return a default value if the variable doesn't exist... $env = env('APP_ENV', 'production'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-get)`get()` 该`get`函数从请求中获取输入项,仅限于GET变量: ~~~ $value = get('key', $default = null) ~~~ #### [](https://octobercms.com/docs/services/helpers#method-input)`input()` 该`input`函数从请求中获取输入项: ~~~ $value = input('key', $default = null) ~~~ #### [](https://octobercms.com/docs/services/helpers#method-post)`post()` 该`post`函数从请求中获取输入项,仅限于POST变量: ~~~ $value = post('key', $default = null) ~~~ #### [](https://octobercms.com/docs/services/helpers#method-redirect)`redirect()` 该`redirect`函数返回重定向器的实例以进行[重定向响应](https://octobercms.com/docs/services/response-view#redirects): ~~~ return redirect('/home'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-request)`request()` 该`request`函数返回当前[请求实例](https://octobercms.com/docs/services/request-input): ~~~ $referer = request()->header('referer'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-response)`response()` 该`response`函数创建[响应](https://octobercms.com/docs/services/response-view)实例或获取响应工厂的实例: ~~~ return response('Hello World', 200, $headers); return response()->json(['foo' => 'bar'], 200, $headers); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-route)`route()` 该`route`函数为给定的[命名路由](https://octobercms.com/docs/services/router)生成一个URL: ~~~ $url = route('routeName'); ~~~ 如果路由接受参数,则可以将它们作为方法的第二个参数传递: ~~~ $url = route('routeName', ['id' => 1]); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-secure-asset)`secure_asset()` 使用HTTPS生成资产的URL: ~~~ echo secure_asset('foo/bar.zip', $title, $attributes = []); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-trace-log)`trace_log()` 该`trace_log`函数将跟踪消息写入日志文件。 ~~~ trace_log('This code has passed...'); ~~~ 该函数支持传递异常,数组和对象: ~~~ trace_log($exception); trace_log($array); trace_log($object); ~~~ 您还可以传递多个参数来跟踪多个消息: ~~~ trace_log($value1, $value2, $exception, '...'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-trace-sql)`trace_sql()` 该`trace_sql`功能启用数据库日志记录并开始监视所有SQL输出。 ~~~ trace_sql(); Db::table('users')->count(); // select count(*) as aggregate from users ~~~ #### [](https://octobercms.com/docs/services/helpers#method-url)`url()` 该`url`函数生成给定路径的标准URL: ~~~ echo url('user/profile'); echo url('user/profile', [1]); ~~~