🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 路径助手函数 ### [](https://octobercms.com/docs/services/helpers#paths)路径 #### [](https://octobercms.com/docs/services/helpers#path-symbols)路径符号 路径前缀符号可用于创建动态路径。例如,以开头的路径`~/`将创建相对于应用程序的路径: ~~~ list: ~/plugins/acme/pay/models/invoiceitem/columns.yaml ~~~ 支持使用以下符号创建动态路径: | 符号 | 描述 | | --- | --- | | `$` | 相对于plugins目录 | | `~` | 相对于应用程序目录 | #### [](https://octobercms.com/docs/services/helpers#method-app-path)`app_path()` 该`app_path`函数返回`app`目录的标准路径: ~~~ $path = app_path(); ~~~ 您还可以使用该`app_path`函数生成相对于应用程序目录的给定文件的标准路径: ~~~ $path = app_path('Http/Controllers/Controller.php'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-base-path)`base_path()` 该`base_path`函数返回到项目根目录的标准路径: ~~~ $path = base_path(); ~~~ 您还可以使用该`base_path`函数生成相对于应用程序目录的给定文件的标准路径: ~~~ $path = base_path('vendor/bin'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-config-path)`config_path($path = '')` 该`config_path`函数返回到应用程序配置目录的标准路径: ~~~ $path = config_path(); ~~~ 您还可以使用该`config_path`函数生成相对于config目录的给定文件的标准路径: ~~~ $path = config_path('dev/cms.php'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-database-path)`database_path()` 该`database_path`函数返回到应用程序数据库目录的标准路径: ~~~ $path = database_path(); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-media-path)`media_path($path = '')` 该`media_path`函数返回到应用程序媒体目录的标准路径: ~~~ $path = media_path(); ~~~ 您还可以使用该`media_path`函数生成相对于媒体目录的给定文件的标准路径: ~~~ $path = media_path('images/myimage.png'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-plugins-path)`plugins_path($path = '')` 该`plugins_path`函数返回到应用程序插件目录的标准路径: ~~~ $path = plugins_path(); ~~~ 您还可以使用该`plugins_path`函数生成相对于plugins目录的给定文件的标准路径: ~~~ $path = plugins_path('author/plugin/routes.php'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-public-path)`public_path()` 该`public_path`函数返回`public`目录的标准路径: ~~~ $path = public_path(); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-storage-path)`storage_path($path = '')` 该`storage_path`函数返回`storage`目录的标准路径: ~~~ $path = storage_path(); ~~~ 您还可以使用该`storage_path`函数生成相对于存储目录的给定文件的标准路径: ~~~ $path = storage_path('app/file.txt'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-temp-path)`temp_path($path = '')` 该`temp_path`函数将临时文件的标准路径返回到可写目录: ~~~ $path = temp_path(); ~~~ 您还可以使用该`temp_path`函数生成相对于temp目录的给定文件的标准路径: ~~~ $path = temp_path('app/file.txt'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-themes-path)`themes_path($path = '')` 该`themes_path`函数返回`themes`目录的标准路径: ~~~ $path = themes_path(); ~~~ 您还可以使用该`themes_path`函数生成相对于主题目录的给定文件的标准路径: ~~~ $path = themes_path('mytheme/file.txt'); ~~~ #### [](https://octobercms.com/docs/services/helpers#method-uploads-path)`uploads_path($path = '')` 该`uploads_path`函数返回应用程序上载目录的标准路径: ~~~ $path = uploads_path(); ~~~ 您还可以使用该`uploads_path`函数生成相对于上载目录的给定文件的标准路径: ~~~ $path = uploads_path('public/file.txt'); ~~~