CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.1 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 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

Namespaces

  • Global
  • 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

Class Asset

Class for generating asset URLs.

Namespace: Cake\Routing

Property Summary

  • $inflectionType protected static
    string

    Inflection type.

Method Summary

  • assetTimestamp() public static

    Adds a timestamp to a file based resource based on the value of Asset.timestamp in Configure. If Asset.timestamp is true and debug is true, or Asset.timestamp === 'force' a timestamp will be added.

  • cssUrl() public static

    Generates URL for given CSS file.

  • encodeUrl() protected static

    Encodes URL parts using rawurlencode().

  • imageUrl() public static

    Generates URL for given image file.

  • inflectString() protected static

    Inflect the theme/plugin name to type set using Asset::setInflectionType().

  • pluginSplit() protected static

    Splits a dot syntax plugin name into its plugin and filename. If $name does not have a dot, then index 0 will be null. It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot.

  • requestWebroot() protected static

    Get webroot from request.

  • scriptUrl() public static

    Generates URL for given javascript file.

  • setInflectionType() public static

    Set inflection type to use when inflecting plugin/theme name.

  • url() public static

    Generates URL for given asset file.

  • webroot() public static

    Checks if a file exists when theme is used, if no file is found default location is returned.

Method Detail

assetTimestamp() ¶ public static

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

Adds a timestamp to a file based resource based on the value of Asset.timestamp in Configure. If Asset.timestamp is true and debug is true, or Asset.timestamp === 'force' a timestamp will be added.

Parameters
string $path

The file path to timestamp, the path must be inside App.wwwRoot in Configure.

string|bool|null $timestamp optional

If set will overrule the value of Asset.timestamp in Configure.

Returns
string

cssUrl() ¶ public static

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

Generates URL for given CSS file.

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
string $path

Path string.

array<string, mixed> $options optional

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs ext Asset extension to append plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.

Returns
string

encodeUrl() ¶ protected static

encodeUrl(string $url): string

Encodes URL parts using rawurlencode().

Parameters
string $url

The URL to encode.

Returns
string

imageUrl() ¶ public static

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

Generates URL for given image file.

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
string $path

Path string.

array<string, mixed> $options optional

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.

Returns
string

inflectString() ¶ protected static

inflectString(string $string): string

Inflect the theme/plugin name to type set using Asset::setInflectionType().

Parameters
string $string

String inflected.

Returns
string

pluginSplit() ¶ protected static

pluginSplit(string $name): array

Splits a dot syntax plugin name into its plugin and filename. If $name does not have a dot, then index 0 will be null. It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot.

Parameters
string $name

The name you want to plugin split.

Returns
array

requestWebroot() ¶ protected static

requestWebroot(): string

Get webroot from request.

Returns
string

scriptUrl() ¶ public static

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

Generates URL for given javascript file.

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
string $path

Path string.

array<string, mixed> $options optional

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs ext Asset extension to append plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.

Returns
string

setInflectionType() ¶ public static

setInflectionType(string $inflectionType): void

Set inflection type to use when inflecting plugin/theme name.

Parameters
string $inflectionType

Inflection type. Value should be a valid method name of Inflector class like 'dasherize' or 'underscore'`.

Returns
void

url() ¶ public static

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

Generates URL for given asset file.

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Options:

  • fullBase Boolean true or a string (e.g. https://example) to return full URL with protocol and domain name.
  • pathPrefix Path prefix for relative URLs
  • ext Asset extension to append
  • plugin False value will prevent parsing path as a plugin
  • theme Optional theme name
  • timestamp Overrides the value of Asset.timestamp in Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.
Parameters
string $path

Path string or URL array

array<string, mixed> $options optional

Options array.

Returns
string

webroot() ¶ public static

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

Checks if a file exists when theme is used, if no file is found default location is returned.

Options:

  • theme Optional theme name
Parameters
string $file

The file to create a webroot path to.

array<string, mixed> $options optional

Options array.

Returns
string

Property Detail

$inflectionType ¶ protected static

Inflection type.

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs