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
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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 méthode

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 méthode

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

addToUrl() public static méthode

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
Résultat string The new URL

classFileExists() protected méthode

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
Résultat boolean True if the class exists

convertRelativeUrls() public static méthode

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
Résultat string The text with the replaced URLs

createInitialVersion() protected méthode

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 méthode

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 méthode

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
Résultat array The page IDs array without the nested IDs

eliminateNestedPaths() protected méthode

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

findContentElement() public static méthode

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
Résultat string The class name

findFrontendModule() public static méthode

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
Résultat string The class name

generateFrontendUrl() public static méthode

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
Résultat string An URL that can be used in the front end

generateImage() public static méthode

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
Résultat string The image HTML tag

generateMargin() public static méthode

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"
Résultat string The CSS markup

getArticle() public static méthode

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
Résultat string | boolean The article HTML markup or false

getBackendLanguages() protected méthode

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
Résultat array An array of available back end languages

getBackendThemes() public static méthode

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
Résultat array An array of available back end themes

getChildRecords() protected méthode

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
Résultat array An array of child record IDs

getContentElement() public static méthode

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
Résultat string The content element HTML markup

getDatePickerString() protected méthode

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
Résultat boolean

getForm() public static méthode

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
Résultat string The form HTML markup

getFrontendModule() public static méthode

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
Résultat string The module HTML markup

getImage() protected méthode

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
Résultat string | null The image path or null

getPageDetails() public static méthode

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
Résultat PageModel The page model or null

getPageSections() public static méthode

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
Résultat array An array of active page sections

getPageStatusIcon() public static méthode

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
Résultat string The status icon name

getParentEntries() protected méthode

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
Résultat string A string that can be used in a log message

getParentRecords() protected méthode

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
Résultat array An array of parent record IDs

getSpellcheckerString() protected méthode

Return the languages for the TinyMCE spellchecker
protected getSpellcheckerString ( ) : string
Résultat string The TinyMCE spellchecker language string

getTemplate() public static méthode

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
Résultat string The path to the template file

getTemplateGroup() public static méthode

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_")
Résultat array An array of template names

getTheme() public static méthode

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
Résultat string The name of the theme

isVisibleElement() public static méthode

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

loadDataContainer() public static méthode

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 méthode

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
Résultat string The attribute or an empty string

optionSelected() public static méthode

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
Résultat string The attribute or an empty string

parseSimpleTokens() protected méthode

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
Résultat string The text with the replaced tokens

prepareForWidget() protected méthode

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
Résultat array An array that can be passed to a widget

printArticleAsPdf() protected méthode

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 méthode

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 méthode

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
Résultat string The URL of the target page

reload() public static méthode

Reload the current page
public static reload ( )

removeOldFeeds() protected méthode

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
Résultat array An array of old XML files

replaceDynamicScriptTags() public static méthode

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

replaceInsertTags() public static méthode

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
Résultat string The text with the replaced tags

replaceOldBePaths() protected static méthode

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

resizeImage() protected méthode

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
Résultat boolean True if the image has been resized correctly

restoreBasicEntities() public static méthode

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
Résultat string The string with the original entities

sendFileToBrowser() public static méthode

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 méthode

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