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
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
      • Exception
      • Middleware
      • Route
    • TestSuite
    • Utility
    • Validation
    • View

资产类

用于生成资产 URL 的类。

命名空间: Cake\Routing

属性摘要

  • $inflectionType protected static
    字符串

    词形变化类型。

方法摘要

  • assetTimestamp() public static

    根据 Configure 中 Asset.timestamp 的值,向基于文件的资源添加时间戳。如果 Asset.timestamp 为 true 且 debug 为 true,或者 Asset.timestamp === 'force',则会添加时间戳。

  • cssUrl() public static

    为给定的 CSS 文件生成 URL。

  • encodeUrl() protected static

    使用 rawurlencode() 编码 URL 部分。

  • imageUrl() public static

    为给定的图像文件生成 URL。

  • inflectString() protected static

    使用 Asset::setInflectionType() 将主题/插件名称词形变化为类型集。

  • pluginSplit() protected static

    将点语法插件名称拆分为其插件和文件名。如果 $name 没有点,则索引 0 将为 null。它检查插件是否已加载,否则文件名将保持不变,以用于包含点的文件名。

  • requestWebroot() protected static

    从请求中获取 webroot。

  • scriptUrl() public static

    为给定的 JavaScript 文件生成 URL。

  • setInflectionType() public static

    设置词形变化类型,在词形变化插件/主题名称时使用。

  • url() public static

    为给定的资产文件生成 URL。

  • webroot() public static

    检查使用主题时文件是否存在,如果找不到文件,则返回默认位置。

方法详细

assetTimestamp() ¶ public static

assetTimestamp(string $path, string|bool $timestamp = null): string

根据 Configure 中 Asset.timestamp 的值,向基于文件的资源添加时间戳。如果 Asset.timestamp 为 true 且 debug 为 true,或者 Asset.timestamp === 'force',则会添加时间戳。

参数
string $path

要添加时间戳的文件路径,路径必须位于 Configure 中的 App.wwwRoot 内。

string|bool $timestamp 可选

如果设置,将覆盖 Configure 中 Asset.timestamp 的值。

返回
字符串

cssUrl() ¶ public static

cssUrl(string $path, array<string, mixed> $options = []): string

为给定的 CSS 文件生成 URL。

根据传递的选项提供带有域名完整 URL。还会调用 Asset::assetTimestamp() 向本地文件添加时间戳。

参数
string $path

路径字符串。

array<string, mixed> $options 可选

选项数组。可能的键:fullBase 返回带有域名完整 URL pathPrefix 相对 URL 的路径前缀 ext 要附加的资产扩展名 plugin False 值将阻止将路径解析为插件 timestamp 覆盖 Configure 中 Asset.timestamp 的值。设置为 false 以跳过时间戳生成。设置为 true 以在 debug 为 true 时应用时间戳。设置为 'force' 以始终启用时间戳,无论 debug 值如何。

返回
字符串

encodeUrl() ¶ protected static

encodeUrl(string $url): string

使用 rawurlencode() 编码 URL 部分。

参数
string $url

要编码的 URL。

返回
字符串

imageUrl() ¶ public static

imageUrl(string $path, array<string, mixed> $options = []): string

为给定的图像文件生成 URL。

根据传递的选项提供带有域名完整 URL。还会调用 Asset::assetTimestamp() 向本地文件添加时间戳。

参数
string $path

路径字符串。

array<string, mixed> $options 可选

选项数组。可能的键:fullBase 返回带有域名完整 URL pathPrefix 相对 URL 的路径前缀 plugin False 值将阻止将路径解析为插件 timestamp 覆盖 Configure 中 Asset.timestamp 的值。设置为 false 以跳过时间戳生成。设置为 true 以在 debug 为 true 时应用时间戳。设置为 'force' 以始终启用时间戳,无论 debug 值如何。

返回
字符串

inflectString() ¶ protected static

inflectString(string $string): string

使用 Asset::setInflectionType() 将主题/插件名称词形变化为类型集。

参数
string $string

词形变化后的字符串。

返回
字符串

pluginSplit() ¶ protected static

pluginSplit(string $name): array

将点语法插件名称拆分为其插件和文件名。如果 $name 没有点,则索引 0 将为 null。它检查插件是否已加载,否则文件名将保持不变,以用于包含点的文件名。

参数
string $name

要插件拆分的名称。

返回
数组

requestWebroot() ¶ protected static

requestWebroot(): string

从请求中获取 webroot。

返回
字符串

scriptUrl() ¶ public static

scriptUrl(string $path, array<string, mixed> $options = []): string

为给定的 JavaScript 文件生成 URL。

根据传递的选项提供带有域名完整 URL。还会调用 Asset::assetTimestamp() 向本地文件添加时间戳。

参数
string $path

路径字符串。

array<string, mixed> $options 可选

选项数组。可能的键:fullBase 返回带有域名完整 URL pathPrefix 相对 URL 的路径前缀 ext 要附加的资产扩展名 plugin False 值将阻止将路径解析为插件 timestamp 覆盖 Configure 中 Asset.timestamp 的值。设置为 false 以跳过时间戳生成。设置为 true 以在 debug 为 true 时应用时间戳。设置为 'force' 以始终启用时间戳,无论 debug 值如何。

返回
字符串

setInflectionType() ¶ public static

setInflectionType(string $inflectionType): void

设置词形变化类型,在词形变化插件/主题名称时使用。

参数
string $inflectionType

词形变化类型。值应为 Inflector 类的有效方法名称,例如 'dasherize' 或 'underscore'`。

返回
空

url() ¶ public static

url(string $path, array<string, mixed> $options = []): string

为给定的资产文件生成 URL。

根据传递的选项提供带有域名完整 URL。还会调用 Asset::assetTimestamp() 向本地文件添加时间戳。

选项

  • fullBase 布尔值 true 或字符串(例如 https://example)以返回带有协议和域名完整 URL。
  • pathPrefix 相对 URL 的路径前缀
  • ext 要附加的资产扩展名
  • plugin False 值将阻止将路径解析为插件
  • theme 可选的主题名称
  • timestamp 覆盖 Configure 中 Asset.timestamp 的值。设置为 false 以跳过时间戳生成。设置为 true 以在 debug 为 true 时应用时间戳。设置为 'force' 以始终启用时间戳,无论 debug 值如何。
参数
string $path

路径字符串或 URL 数组

array<string, mixed> $options 可选

选项数组。

返回
字符串

webroot() ¶ public static

webroot(string $file, array<string, mixed> $options = []): string

检查使用主题时文件是否存在,如果找不到文件,则返回默认位置。

选项

  • theme 可选的主题名称
参数
string $file

要创建 webroot 路径的文件。

array<string, mixed> $options 可选

选项数组。

返回
字符串

属性详细

$inflectionType ¶ protected static

词形变化类型。

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

使用 CakePHP API 文档 生成