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
    • TestSuite
    • Utility
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

类 UrlHelper

用于生成 URL 的 UrlHelper 类。

命名空间: Cake\View\Helper

属性摘要

  • $_View protected
    Cake\View\View

    此助手附加到的 View 实例

  • $_assetUrlClassName protected
    string

    资产 URL 引擎类名

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    配置属性是否已使用默认值进行配置

  • $_defaultConfig protected
    array<string, mixed>

    此类的默认配置

  • $helperInstances protected
    array<string,Cake\View\Helper>

    加载的助手实例。

  • $helpers protected
    array

    此助手使用的助手列表

方法摘要

  • __construct() public

    默认构造函数

  • __debugInfo() public

    返回一个数组,可用于描述此对象的内部状态。

  • __get() public

    延迟加载助手。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _confirm() protected

    返回一个字符串,用作确认对话框的 onclick 处理程序。

  • addClass() public

    将给定类添加到元素选项

  • assetTimestamp() public

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

  • assetUrl() public

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

  • build() public

    根据提供的参数返回 URL。

  • buildFromPath() public

    从路由路径字符串返回 URL。

  • configShallow() public

    将提供的配置与现有配置合并。与 config() 对嵌套键进行递归合并不同,此方法执行简单合并。

  • css() public

    为给定的 CSS 文件生成 URL。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getView() public

    获取此助手绑定的 View 实例。

  • image() public

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

  • implementedEvents() public

    事件监听器。

  • initialize() public

    检查正确的配置

  • script() public

    为给定的 javascript 文件生成 URL。

  • setConfig() public

    设置配置。

  • webroot() public

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

方法详情

__construct() ¶ public

__construct(Cake\View\View $view, array<string, mixed> $config = [])

默认构造函数

参数
Cake\View\View $view

此助手附加到的 View。

array<string, mixed> $config 可选

助手的配置设置。

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

返回一个数组,可用于描述此对象的内部状态。

返回值
array<string, mixed>

__get() ¶ public

__get(string $name): Cake\View\Helper|null

延迟加载助手。

参数
string $name

正在访问的属性的名称。

返回值
Cake\View\Helper|null

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回值
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge 可选

如果为 True 则递归合并,如果为 'shallow' 则简单合并,如果为 False 则覆盖,默认为 False。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_confirm() ¶ protected

_confirm(string $okCode, string $cancelCode): string

返回一个字符串,用作确认对话框的 onclick 处理程序。

参数
string $okCode

用户选择“确定”后要执行的代码

string $cancelCode

用户选择“取消”后要执行的代码

返回值
string

addClass() ¶ public

addClass(array<string, mixed> $options, string $class, string $key = 'class'): array<string, mixed>

将给定类添加到元素选项

参数
array<string, mixed> $options

要添加类的数组选项/属性

string $class

正在添加的类名。

string $key 可选

用于类的键,默认为 'class'。

返回值
array<string, mixed>

assetTimestamp() ¶ public

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 的值。

返回值
string

assetUrl() ¶ public

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

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

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

选项

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

路径字符串或 URL 数组

array<string, mixed> $options 可选

选项数组。

返回值
string

build() ¶ public

build(array|string|null $url = null, array<string, mixed> $options = []): string

根据提供的参数返回 URL。

选项

  • escape: 如果为 false,则返回未转义的 URL,仅在之后手动转义后才能显示。
  • fullBase: 如果为 true,则完整的基本 URL 将被追加到结果中
参数
array|string|null $url 可选

可以是类似 /products/view/23 的相对字符串 URL,也可以是 URL 参数的数组。使用数组作为 URL 将使您能够利用 CakePHP 的反向路由功能。

array<string, mixed> $options 可选

选项数组。

返回值
string

buildFromPath() ¶ public

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

从路由路径字符串返回 URL。

选项

  • escape: 如果为 false,则返回未转义的 URL,仅在之后手动转义后才能显示。
  • fullBase: 如果为 true,则完整的基本 URL 将被追加到结果中
参数
string $path

Cake 相对路由路径。

array $params 可选

一个指定任何额外参数的数组。也可以是 `Router::url()` 支持的任何特殊参数。

array<string, mixed> $options 可选

选项数组。

返回值
string
参见
\Cake\Routing\Router::pathUrl()

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config() 对嵌套键进行递归合并不同,此方法执行简单合并。

设置一个特定值

$this->configShallow('key', $value);

设置一个嵌套值

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或一个完整的配置数组。

mixed|null $value 可选

要设置的值。

返回值
$this

css() ¶ public

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

为给定的 CSS 文件生成 URL。

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

参数
string $path

路径字符串。

array<string, mixed> $options 可选

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

返回值
string

getConfig() ¶ public

getConfig(string|null $key = null, mixed $default = null): mixed

返回配置。

用法

读取整个配置

$this->getConfig();

读取一个特定值

$this->getConfig('key');

读取一个嵌套值

$this->getConfig('some.nested.key');

使用默认值读取

$this->getConfig('some-key', 'default-value');
参数
string|null $key 可选

要获取的键,或用于整个配置的 null。

mixed $default 可选

键不存在时的返回值。

返回值
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,不能为 null。

参数
string $key

要获取的键。

返回值
mixed
抛出
InvalidArgumentException

getView() ¶ public

getView(): Cake\View\View

获取此助手绑定的 View 实例。

返回值
Cake\View\View

image() ¶ public

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

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

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

参数
string $path

路径字符串。

array<string, mixed> $options 可选

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

返回值
string

implementedEvents() ¶ public

implementedEvents(): array<string, mixed>

事件监听器。

通过定义一个回调方法,假设助手对相关事件感兴趣。

如果您需要添加非传统事件监听器,请覆盖此方法。或者如果您想让助手监听非标准事件。

返回值
array<string, mixed>

initialize() ¶ public

initialize(array<string, mixed> $config): void

检查正确的配置

实现此方法以避免覆盖构造函数并调用父类。

参数
array<string, mixed> $config

提供给此助手的配置设置。

返回值
void

script() ¶ public

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

为给定的 javascript 文件生成 URL。

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

参数
string $path

路径字符串。

array<string, mixed> $options 可选

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

返回值
string

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置一个特定值

$this->setConfig('key', $value);

设置一个嵌套值

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或一个完整的配置数组。

mixed|null $value 可选

要设置的值。

bool $merge 可选

是否递归合并或覆盖现有配置,默认值为 true。

返回值
$this
抛出
Cake\Core\Exception\CakeException
尝试设置无效键时。

webroot() ¶ public

webroot(string $file): string

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

参数
string $file

要创建 webroot 路径的文件。

返回值
string

属性详细信息

$_View ¶ protected

此助手附加到的 View 实例

类型
Cake\View\View

$_assetUrlClassName ¶ protected

资产 URL 引擎类名

类型
string

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

配置属性是否已使用默认值进行配置

类型
bool

$_defaultConfig ¶ protected

此类的默认配置

类型
array<string, mixed>

$helperInstances ¶ protected

加载的助手实例。

类型
array<string,Cake\View\Helper>

$helpers ¶ protected

此助手使用的助手列表

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

使用 CakePHP API 文档 生成