HeaderHelper

Type
Class
Namespace
Craft
Inherits
Craft\HeaderHelper
Since
1.3

Class HeaderHelper

See also http://craftcms.com

View source

Public Methods

MethodDescription
getHeader()Returns the value of a given header, if it has been set.
getMimeType()Returns the MIME type that is going to be included in the response via the Content-Type header, whether that has been set explicitly in the PHP code or if it's going to be based on the default_mimetype setting in php.ini.
isHeaderSet()Checks whether a header is currently set or not.
removeHeader()Removes a header by key.
setContentTypeByExtension()Sets the Content-Type header based on a file extension.
setDownload()Forces a file download. Be sure to give the right extension.
setExpires()Tells the browser not to request this content again the next $sec seconds but use the browser cached content.
setHeader()Called to output a header.
setLength()Tells the browser the length of the following content. This mostly makes sense when using the download function so the browser can calculate how many bytes are left during the process.
setNoCache()Tells the browser not to cache the following content
setPrivate()Tells the browser that the following content is private
setPublic()Tells the browser that the following content is public

getHeader()

Returns the value of a given header, if it has been set.

View source

Arguments

  • $name (string) – The name of the header.

Returns

string, null – The value of the header, or null if it hasn’t been set.

Signature

public static string, null getHeader ( $name )

getMimeType()

Returns the MIME type that is going to be included in the response via the Content-Type header, whether that has been set explicitly in the PHP code or if it's going to be based on the default_mimetype setting in php.ini.

View source

Returns

string

Signature

public static string getMimeType ( )

isHeaderSet()

Checks whether a header is currently set or not.

View source

Arguments

Returns

boolean

Signature

public static boolean isHeaderSet ( $name )

removeHeader()

Removes a header by key.

View source

Arguments

  • $key

Returns

null

Signature

public static null removeHeader ( $key )

setContentTypeByExtension()

Sets the Content-Type header based on a file extension.

View source

Arguments

Returns

boolean – Whether setting the header was successful.

Signature

public static boolean setContentTypeByExtension ( $extension )

setDownload()

Forces a file download. Be sure to give the right extension.

View source

Arguments

  • $fileName (string) – The name of the file when it's downloaded
  • $fileSize (integer) – The size in bytes.

Returns

null

Signature

public static null setDownload ( $fileName, $fileSize = null )

setExpires()

Tells the browser not to request this content again the next $sec seconds but use the browser cached content.

View source

Arguments

  • $seconds (integer) – Time in seconds to hold in browser cache

Returns

null

Signature

public static null setExpires ( $seconds = 300 )

setHeader()

Called to output a header.

View source

Arguments

  • $header (array) – Use key => value

Returns

null

Signature

public static null setHeader ( $header )

setLength()

Tells the browser the length of the following content. This mostly makes sense when using the download function so the browser can calculate how many bytes are left during the process.

View source

Arguments

  • $sizeInBytes (integer) – The content size in bytes

Returns

null

Signature

public static null setLength ( $sizeInBytes )

setNoCache()

Tells the browser not to cache the following content

View source

Returns

null

Signature

public static null setNoCache ( )

setPrivate()

Tells the browser that the following content is private

View source

Returns

null

Signature

public static null setPrivate ( )

setPublic()

Tells the browser that the following content is public

View source

Returns

null

Signature

public static null setPublic ( )