CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 自驾游
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题(Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • LinkedIn
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • 缓存
    • 集合
    • 命令
    • 控制台
    • 控制器
    • 核心
      • 配置
      • 异常
      • 重试
      • 测试套件
    • 数据库
    • 数据源
    • 错误
    • 事件
    • 表单
    • HTTP
    • 国际化
    • 日志
    • 邮件
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 工具
    • 验证
    • 视图

类 App

App 负责资源定位和路径管理。

添加路径

现在使用 Configure 配置模板和插件的附加路径。请参阅 config/app.php 获取示例。App.paths.plugins 和 App.paths.templates 变量分别用于配置插件和模板的路径。所有基于类的资源应使用应用程序的自动加载器进行映射。

检查已加载的路径

您可以使用 App::classPath('Controller') 等来检查当前加载的路径,以查看加载的控制器路径。

也可以检查插件类的路径,例如,要获取插件帮助器的路径,您可以调用 App::classPath('View/Helper', 'MyPlugin')

定位插件

也可以使用 App 定位插件。例如,使用 Plugin::path('DebugKit') 将会为您提供 DebugKit 插件的完整路径。

命名空间: Cake\Core
链接: https://book.cakephp.com.cn/5/en/core-libraries/app.html

方法概要

  • _classExistsInBase() protected static

    _classExistsInBase

  • className() public static

    返回带命名空间的类名。此方法检查类是否在应用程序/插件中定义,否则尝试从 CakePHP 核心加载

  • classPath() public static

    获取应用程序或插件中类类型的路径。

  • core() public static

    返回 CakePHP 核心内部包的完整路径

  • path() public static

    用于读取存储路径的信息。

  • shortName() public static

    返回类的插件拆分名称

方法详情

_classExistsInBase() ¶ protected static

_classExistsInBase(string $name, string $namespace): bool

_classExistsInBase

测试隔离包装器

参数
string $name

类名。

string $namespace

命名空间。

返回值
bool

className() ¶ public static

className(string $class, string $type = '', string $suffix = ''): class-string|null

返回带命名空间的类名。此方法检查类是否在应用程序/插件中定义,否则尝试从 CakePHP 核心加载

参数
string $class

类名

string $type optional

类类型

string $suffix optional

类名后缀

返回值
class-string|null

classPath() ¶ public static

classPath(string $type, string|null $plugin = null): list<string>

获取应用程序或插件中类类型的路径。

示例

App::classPath('Model/Table');

将返回表的路径 - 例如 src/Model/Table/。

App::classPath('Model/Table', 'My/Plugin');

将返回基于插件的路径。

参数
string $type

包类型。

string|null $plugin optional

插件名称。

返回值
list<string>

core() ¶ public static

core(string $type): list<string>

返回 CakePHP 核心内部包的完整路径

用法

App::core('Cache/Engine');

将返回缓存引擎包的完整路径。

参数
string $type

包类型。

返回值
list<string>

path() ¶ public static

path(string $type, string|null $plugin = null): array<int|string, string>

用于读取存储路径的信息。

当不带 $plugin 参数调用时,它将返回 App.paths.$type 配置的值。

默认类型

  • 插件
  • 模板
  • 语言

示例

App::path('plugins');

将返回 App.paths.plugins 配置的值。

对于插件,它可以用于获取 templates 或 locales 类型的路径。

参数
string $type

路径类型

string|null $plugin optional

插件名称

返回值
array<int|string, string>
链接
https://book.cakephp.com.cn/5/en/core-libraries/app.html#finding-paths-to-namespaces

shortName() ¶ public static

shortName(string $class, string $type, string $suffix = ''): string

返回类的插件拆分名称

示例

App::shortName(
    'SomeVendor\SomePlugin\Controller\Component\TestComponent',
    'Controller/Component',
    'Component'
)

返回值:SomeVendor/SomePlugin.Test

App::shortName(
    'SomeVendor\SomePlugin\Controller\Component\Subfolder\TestComponent',
    'Controller/Component',
    'Component'
)

返回值:SomeVendor/SomePlugin.Subfolder/Test

App::shortName(
    'Cake\Controller\Component\FlashComponent',
    'Controller/Component',
    'Component'
)

返回值:Flash

参数
string $class

类名

string $type

类类型

string $suffix optional

类名后缀

返回值
string
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题(Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • LinkedIn
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成