PHP Class Contao\Controller

Some of the methods have been made static in Contao 3 and can be used in non-object context as well. Usage: echo Controller::getTheme(); Inside a controller: public function generate() { return $this->getArticle(2); }
Inheritance: extends System
Show file Open project: contao/core-bundle Class Usage Examples

Public Methods

Method Description
addEnclosuresToTemplate ( object $objTemplate, array $arrItem, string $strKey = 'enclosure' ) Add enclosures to a template
addImageToTemplate ( object $objTemplate, array $arrItem, integer $intMaxWidth = null, string $strLightboxId = null ) Add an image to a template
addStaticUrlTo ( string $script ) : string Add a static URL to a script
addToUrl ( string $strRequest, boolean $blnAddRef = true, array $arrUnset = [] ) : string Add a request string to the current URL
convertRelativeUrls ( string $strContent, string $strBase = '', boolean $blnHrefOnly = false ) : string Convert relative URLs in href and src attributes to absolute URLs
findContentElement ( string $strName ) : string Find a content element in the TL_CTE array and return the class name
findFrontendModule ( string $strName ) : string Find a front end module in the FE_MOD array and return the class name
generateFrontendUrl ( array $arrRow, string $strParams = null, string $strForceLang = null, boolean $blnFixDomain = false ) : string Generate a front end URL
generateImage ( string $src, string $alt = '', string $attributes = '' ) : string Generate an image tag and return it as string
generateMargin ( array $arrValues, string $strType = 'margin' ) : string Compile the margin format definition based on an array of values
getArticle ( mixed $varId, boolean $blnMultiMode = false, boolean $blnIsInsertTag = false, string $strColumn = 'main' ) : string | boolean Generate an article and return it as string
getBackendThemes ( ) : array Return the back end themes as array
getContentElement ( mixed $intId, string $strColumn = 'main' ) : string Generate a content element and return it as string
getForm ( mixed $varId, string $strColumn = 'main' ) : string Generate a form and return it as string
getFrontendModule ( mixed $intId, string $strColumn = 'main' ) : string Generate a front end module and return it as string
getPageDetails ( mixed $intId ) : PageModel Get the details of a page including inherited parameters
getPageSections ( ) : array Return all page sections as array
getPageStatusIcon ( PageModel | Result | object $objPage ) : string Calculate the page status icon name based on the page parameters
getTemplate ( string $strTemplate, string $strFormat = 'html5' ) : string Find a particular template file and return its path
getTemplateGroup ( string $strPrefix ) : array Return all template files of a particular group as array
getTheme ( ) : string Return the current theme as string
isVisibleElement ( Model $objElement ) : boolean Check whether an element is visible in the front end
loadDataContainer ( string $strTable, boolean $blnNoCache = false ) Load a set of DCA files
optionChecked ( string $strOption, mixed $varValues ) : string Return a "checked" attribute if the option is checked
optionSelected ( string $strOption, mixed $varValues ) : string Return a "selected" attribute if the option is selected
redirect ( string $strLocation, integer $intStatus = 303 ) Redirect to another page
reload ( ) Reload the current page
replaceDynamicScriptTags ( string $strBuffer ) : string Replace the dynamic script tags (see #4203)
replaceInsertTags ( string $strBuffer, boolean $blnCache = true ) : string Replace insert tags with their values
restoreBasicEntities ( string $strBuffer ) : string Restore basic entities
sendFileToBrowser ( string $strFile ) Send a file to the browser so the "save as …" dialogue opens
setStaticUrls ( PageModel $objPage = null ) Set the static URL constants

Protected Methods

Method Description
classFileExists ( string $strClass ) : boolean Return true if a class exists (tries to autoload the class)
createInitialVersion ( string $strTable, integer $intId ) Create an initial version of a record
createNewVersion ( string $strTable, integer $intId ) Create a new version of a record
eliminateNestedPages ( array $arrPages, string $strTable = null, boolean $blnSorting = false ) : array Take an array of pages and eliminate the nested ones
eliminateNestedPaths ( array $arrPaths ) : array Take an array of file paths and eliminate the nested ones
getBackendLanguages ( ) : array Return the installed back end languages as array
getChildRecords ( mixed $arrParentIds, string $strTable, boolean $blnSorting = false, array $arrReturn = [], string $strWhere = '' ) : array Return the IDs of all child records of a particular record (see #2475)
getDatePickerString ( ) : boolean Return the date picker string (see #3218)
getImage ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null Resize an image and crop it if necessary
getParentEntries ( string $strTable, integer $intId ) : string Get the parent records of an entry and return them as string which can be used in a log message
getParentRecords ( integer $intId, string $strTable ) : array Return the IDs of all parent records of a particular record
getSpellcheckerString ( ) : string Return the languages for the TinyMCE spellchecker
parseSimpleTokens ( string $strBuffer, array $arrData ) : string Parse simple tokens that can be used to personalize newsletters
prepareForWidget ( array $arrData, string $strName, mixed $varValue = null, string $strField = '', string $strTable = '' ) : array Convert a DCA file configuration to be used with widgets
printArticleAsPdf ( ModuleModel $objArticle ) Print an article as PDF and stream it to the browser
redirectToFrontendPage ( integer $intPage, mixed $varArticle = null, boolean $blnReturn = false ) : string Redirect to a front end page
removeOldFeeds ( boolean $blnReturn = false ) : array Remove old XML files from the share directory
replaceOldBePaths ( string $strContext ) : string Replace the old back end paths
resizeImage ( string $image, integer $width, integer $height, string $mode = '' ) : boolean Resize an image and crop it if necessary

Method Details

addEnclosuresToTemplate() public static method

Add enclosures to a template
public static addEnclosuresToTemplate ( object $objTemplate, array $arrItem, string $strKey = 'enclosure' )
$objTemplate object The template object to add the enclosures to
$arrItem array The element or module as array
$strKey string The name of the enclosures field in $arrItem

addImageToTemplate() public static method

Add an image to a template
public static addImageToTemplate ( object $objTemplate, array $arrItem, integer $intMaxWidth = null, string $strLightboxId = null )
$objTemplate object The template object to add the image to
$arrItem array The element or module as array
$intMaxWidth integer An optional maximum width of the image
$strLightboxId string An optional lightbox ID

addStaticUrlTo() public static method

Add a static URL to a script
public static addStaticUrlTo ( string $script ) : string
$script string The script path
return string The script path with the static URL

addToUrl() public static method

Add a request string to the current URL
public static addToUrl ( string $strRequest, boolean $blnAddRef = true, array $arrUnset = [] ) : string
$strRequest string The string to be added
$blnAddRef boolean Add the referer ID
$arrUnset array An optional array of keys to unset
return string The new URL

classFileExists() protected method

Return true if a class exists (tries to autoload the class)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use the PHP function class_exists() instead.
protected classFileExists ( string $strClass ) : boolean
$strClass string The class name
return boolean True if the class exists

convertRelativeUrls() public static method

Convert relative URLs in href and src attributes to absolute URLs
public static convertRelativeUrls ( string $strContent, string $strBase = '', boolean $blnHrefOnly = false ) : string
$strContent string The text with the URLs to be converted
$strBase string An optional base URL
$blnHrefOnly boolean If true, only href attributes will be converted
return string The text with the replaced URLs

createInitialVersion() protected method

Create an initial version of a record
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Versions->initialize() instead.
protected createInitialVersion ( string $strTable, integer $intId )
$strTable string The table name
$intId integer The ID of the element to be versioned

createNewVersion() protected method

Create a new version of a record
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Versions->create() instead.
protected createNewVersion ( string $strTable, integer $intId )
$strTable string The table name
$intId integer The ID of the element to be versioned

eliminateNestedPages() protected method

Take an array of pages and eliminate the nested ones
protected eliminateNestedPages ( array $arrPages, string $strTable = null, boolean $blnSorting = false ) : array
$arrPages array The array of page IDs
$strTable string The table name
$blnSorting boolean True if the table has a sorting field
return array The page IDs array without the nested IDs

eliminateNestedPaths() protected method

Take an array of file paths and eliminate the nested ones
protected eliminateNestedPaths ( array $arrPaths ) : array
$arrPaths array The array of file paths
return array The file paths array without the nested paths

findContentElement() public static method

Find a content element in the TL_CTE array and return the class name
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use ContentElement::findClass() instead.
public static findContentElement ( string $strName ) : string
$strName string The content element name
return string The class name

findFrontendModule() public static method

Find a front end module in the FE_MOD array and return the class name
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Module::findClass() instead.
public static findFrontendModule ( string $strName ) : string
$strName string The front end module name
return string The class name

generateFrontendUrl() public static method

Generate a front end URL
Deprecation: Deprecated since Contao 4.2, to be removed in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.
public static generateFrontendUrl ( array $arrRow, string $strParams = null, string $strForceLang = null, boolean $blnFixDomain = false ) : string
$arrRow array An array of page parameters
$strParams string An optional string of URL parameters
$strForceLang string Force a certain language
$blnFixDomain boolean Check the domain of the target page and append it if necessary
return string An URL that can be used in the front end

generateImage() public static method

Generate an image tag and return it as string
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Image::getHtml() instead.
public static generateImage ( string $src, string $alt = '', string $attributes = '' ) : string
$src string The image path
$alt string An optional alt attribute
$attributes string A string of other attributes
return string The image HTML tag

generateMargin() public static method

Compile the margin format definition based on an array of values
public static generateMargin ( array $arrValues, string $strType = 'margin' ) : string
$arrValues array An array of four values and a unit
$strType string Either "margin" or "padding"
return string The CSS markup

getArticle() public static method

Generate an article and return it as string
public static getArticle ( mixed $varId, boolean $blnMultiMode = false, boolean $blnIsInsertTag = false, string $strColumn = 'main' ) : string | boolean
$varId mixed The article ID or a Model object
$blnMultiMode boolean If true, only teasers will be shown
$blnIsInsertTag boolean If true, there will be no page relation
$strColumn string The name of the column
return string | boolean The article HTML markup or false

getBackendLanguages() protected method

Return the installed back end languages as array
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use System::getLanguages(true) instead.
protected getBackendLanguages ( ) : array
return array An array of available back end languages

getBackendThemes() public static method

Return the back end themes as array
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Backend::getThemes() instead.
public static getBackendThemes ( ) : array
return array An array of available back end themes

getChildRecords() protected method

Return the IDs of all child records of a particular record (see #2475)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database::getChildRecords() instead.
Author: Andreas Schempp
protected getChildRecords ( mixed $arrParentIds, string $strTable, boolean $blnSorting = false, array $arrReturn = [], string $strWhere = '' ) : array
$arrParentIds mixed An array of parent IDs
$strTable string The table name
$blnSorting boolean True if the table has a sorting field
$arrReturn array The array to be returned
$strWhere string Additional WHERE condition
return array An array of child record IDs

getContentElement() public static method

Generate a content element and return it as string
public static getContentElement ( mixed $intId, string $strColumn = 'main' ) : string
$intId mixed A content element ID or a Model object
$strColumn string The column the element is in
return string The content element HTML markup

getDatePickerString() protected method

Return the date picker string (see #3218)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Specify "datepicker"=>true in your DCA file instead.
protected getDatePickerString ( ) : boolean
return boolean

getForm() public static method

Generate a form and return it as string
public static getForm ( mixed $varId, string $strColumn = 'main' ) : string
$varId mixed A form ID or a Model object
$strColumn string The column the form is in
return string The form HTML markup

getFrontendModule() public static method

Generate a front end module and return it as string
public static getFrontendModule ( mixed $intId, string $strColumn = 'main' ) : string
$intId mixed A module ID or a Model object
$strColumn string The name of the column
return string The module HTML markup

getImage() protected method

Resize an image and crop it if necessary
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Image::get() instead.
protected getImage ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null
$image string The image path
$width integer The target width
$height integer The target height
$mode string An optional resize mode
$target string An optional target to be replaced
$force boolean Override existing target images
return string | null The image path or null

getPageDetails() public static method

Get the details of a page including inherited parameters
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use PageModel::findWithDetails() or PageModel->loadDetails() instead.
public static getPageDetails ( mixed $intId ) : PageModel
$intId mixed A page ID or a Model object
return PageModel The page model or null

getPageSections() public static method

Return all page sections as array
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. See https://github.com/contao/core/issues/4693.
public static getPageSections ( ) : array
return array An array of active page sections

getPageStatusIcon() public static method

Calculate the page status icon name based on the page parameters
public static getPageStatusIcon ( PageModel | Result | object $objPage ) : string
$objPage PageModel | Result | object The page object
return string The status icon name

getParentEntries() protected method

Get the parent records of an entry and return them as string which can be used in a log message
protected getParentEntries ( string $strTable, integer $intId ) : string
$strTable string The table name
$intId integer The record ID
return string A string that can be used in a log message

getParentRecords() protected method

Return the IDs of all parent records of a particular record
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database::getParentRecords() instead.
protected getParentRecords ( integer $intId, string $strTable ) : array
$intId integer The ID of the record
$strTable string The table name
return array An array of parent record IDs

getSpellcheckerString() protected method

Return the languages for the TinyMCE spellchecker
protected getSpellcheckerString ( ) : string
return string The TinyMCE spellchecker language string

getTemplate() public static method

Find a particular template file and return its path
public static getTemplate ( string $strTemplate, string $strFormat = 'html5' ) : string
$strTemplate string The name of the template
$strFormat string The file extension
return string The path to the template file

getTemplateGroup() public static method

Return all template files of a particular group as array
public static getTemplateGroup ( string $strPrefix ) : array
$strPrefix string The template name prefix (e.g. "ce_")
return array An array of template names

getTheme() public static method

Return the current theme as string
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Backend::getTheme() instead.
public static getTheme ( ) : string
return string The name of the theme

isVisibleElement() public static method

Check whether an element is visible in the front end
public static isVisibleElement ( Model $objElement ) : boolean
$objElement Model The element model
return boolean True if the element is visible

loadDataContainer() public static method

Load a set of DCA files
public static loadDataContainer ( string $strTable, boolean $blnNoCache = false )
$strTable string The table name
$blnNoCache boolean If true, the cache will be bypassed

optionChecked() public static method

Return a "checked" attribute if the option is checked
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Widget::optionChecked() instead.
public static optionChecked ( string $strOption, mixed $varValues ) : string
$strOption string The option to check
$varValues mixed One or more values to check against
return string The attribute or an empty string

optionSelected() public static method

Return a "selected" attribute if the option is selected
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Widget::optionSelected() instead.
public static optionSelected ( string $strOption, mixed $varValues ) : string
$strOption string The option to check
$varValues mixed One or more values to check against
return string The attribute or an empty string

parseSimpleTokens() protected method

Parse simple tokens that can be used to personalize newsletters
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use StringUtil::parseSimpleTokens() instead.
protected parseSimpleTokens ( string $strBuffer, array $arrData ) : string
$strBuffer string The text with the tokens to be replaced
$arrData array The replacement data as array
return string The text with the replaced tokens

prepareForWidget() protected method

Convert a DCA file configuration to be used with widgets
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Widget::getAttributesFromDca() instead.
protected prepareForWidget ( array $arrData, string $strName, mixed $varValue = null, string $strField = '', string $strTable = '' ) : array
$arrData array The field configuration array
$strName string The field name in the form
$varValue mixed The field value
$strField string The field name in the database
$strTable string The table name
return array An array that can be passed to a widget

printArticleAsPdf() protected method

Print an article as PDF and stream it to the browser
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use ModuleArticle->generatePdf() instead.
protected printArticleAsPdf ( ModuleModel $objArticle )
$objArticle ModuleModel An article object

redirect() public static method

Redirect to another page
public static redirect ( string $strLocation, integer $intStatus = 303 )
$strLocation string The target URL
$intStatus integer The HTTP status code (defaults to 303)

redirectToFrontendPage() protected method

Redirect to a front end page
protected redirectToFrontendPage ( integer $intPage, mixed $varArticle = null, boolean $blnReturn = false ) : string
$intPage integer The page ID
$varArticle mixed An optional article alias
$blnReturn boolean If true, return the URL and don't redirect
return string The URL of the target page

reload() public static method

Reload the current page
public static reload ( )

removeOldFeeds() protected method

Remove old XML files from the share directory
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Automator::purgeXmlFiles() instead.
protected removeOldFeeds ( boolean $blnReturn = false ) : array
$blnReturn boolean If true, only return the finds and don't delete
return array An array of old XML files

replaceDynamicScriptTags() public static method

Replace the dynamic script tags (see #4203)
public static replaceDynamicScriptTags ( string $strBuffer ) : string
$strBuffer string The string with the tags to be replaced
return string The string with the replaced tags

replaceInsertTags() public static method

Replace insert tags with their values
public static replaceInsertTags ( string $strBuffer, boolean $blnCache = true ) : string
$strBuffer string The text with the tags to be replaced
$blnCache boolean If false, non-cacheable tags will be replaced
return string The text with the replaced tags

replaceOldBePaths() protected static method

Replace the old back end paths
protected static replaceOldBePaths ( string $strContext ) : string
$strContext string The context
return string The modified context

resizeImage() protected method

Resize an image and crop it if necessary
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Image::resize() instead.
protected resizeImage ( string $image, integer $width, integer $height, string $mode = '' ) : boolean
$image string The image path
$width integer The target width
$height integer The target height
$mode string An optional resize mode
return boolean True if the image has been resized correctly

restoreBasicEntities() public static method

Restore basic entities
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use StringUtil::restoreBasicEntities() instead.
public static restoreBasicEntities ( string $strBuffer ) : string
$strBuffer string The string with the tags to be replaced
return string The string with the original entities

sendFileToBrowser() public static method

Send a file to the browser so the "save as …" dialogue opens
public static sendFileToBrowser ( string $strFile )
$strFile string The file path

setStaticUrls() public static method

Set the static URL constants
public static setStaticUrls ( PageModel $objPage = null )
$objPage PageModel An optional page object