HeaderHelper

Type
Class
Namespace
Craft
Inherits
Craft\HeaderHelper
Since
1.3

Class HeaderHelper

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
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 (opens new window)

Arguments

Returns

string (opens new window), null (opens new window) – 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 (opens new window)

Returns

string (opens new window)

Signature

public static string getMimeType ( )

# isHeaderSet()

Checks whether a header is currently set or not.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public static boolean isHeaderSet ( $name )

# removeHeader()

Removes a header by key.

View source (opens new window)

Arguments

  • $key

Returns

null (opens new window)

Signature

public static null removeHeader ( $key )

# setContentTypeByExtension()

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

View source (opens new window)

Arguments

Returns

boolean (opens new window) – 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 (opens new window)

Arguments

Returns

null (opens new window)

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 (opens new window)

Arguments

Returns

null (opens new window)

Signature

public static null setExpires ( $seconds = 300 )

# setHeader()

Called to output a header.

View source (opens new window)

Arguments

Returns

null (opens new window)

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 (opens new window)

Arguments

Returns

null (opens new window)

Signature

public static null setLength ( $sizeInBytes )

# setNoCache()

Tells the browser not to cache the following content

View source (opens new window)

Returns

null (opens new window)

Signature

public static null setNoCache ( )

# setPrivate()

Tells the browser that the following content is private

View source (opens new window)

Returns

null (opens new window)

Signature

public static null setPrivate ( )

# setPublic()

Tells the browser that the following content is public

View source (opens new window)

Returns

null (opens new window)

Signature

public static null setPublic ( )