PHP Класс 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); }
Наследование: extends System
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
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

Описание методов

addEnclosuresToTemplate() публичный статический Метод

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() публичный статический Метод

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() публичный статический Метод

Add a static URL to a script
public static addStaticUrlTo ( string $script ) : string
$script string The script path
Результат string The script path with the static URL

addToUrl() публичный статический Метод

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
Результат string The new URL

classFileExists() защищенный Метод

Return true if a class exists (tries to autoload the class)
Устаревший: 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
Результат boolean True if the class exists

convertRelativeUrls() публичный статический Метод

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
Результат string The text with the replaced URLs

createInitialVersion() защищенный Метод

Create an initial version of a record
Устаревший: 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() защищенный Метод

Create a new version of a record
Устаревший: 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() защищенный Метод

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
Результат array The page IDs array without the nested IDs

eliminateNestedPaths() защищенный Метод

Take an array of file paths and eliminate the nested ones
protected eliminateNestedPaths ( array $arrPaths ) : array
$arrPaths array The array of file paths
Результат array The file paths array without the nested paths

findContentElement() публичный статический Метод

Find a content element in the TL_CTE array and return the class name
Устаревший: 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
Результат string The class name

findFrontendModule() публичный статический Метод

Find a front end module in the FE_MOD array and return the class name
Устаревший: 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
Результат string The class name

generateFrontendUrl() публичный статический Метод

Generate a front end URL
Устаревший: 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
Результат string An URL that can be used in the front end

generateImage() публичный статический Метод

Generate an image tag and return it as string
Устаревший: 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
Результат string The image HTML tag

generateMargin() публичный статический Метод

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"
Результат string The CSS markup

getArticle() публичный статический Метод

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
Результат string | boolean The article HTML markup or false

getBackendLanguages() защищенный Метод

Return the installed back end languages as array
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use System::getLanguages(true) instead.
protected getBackendLanguages ( ) : array
Результат array An array of available back end languages

getBackendThemes() публичный статический Метод

Return the back end themes as array
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Backend::getThemes() instead.
public static getBackendThemes ( ) : array
Результат array An array of available back end themes

getChildRecords() защищенный Метод

Return the IDs of all child records of a particular record (see #2475)
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database::getChildRecords() instead.
Автор: 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
Результат array An array of child record IDs

getContentElement() публичный статический Метод

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
Результат string The content element HTML markup

getDatePickerString() защищенный Метод

Return the date picker string (see #3218)
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Specify "datepicker"=>true in your DCA file instead.
protected getDatePickerString ( ) : boolean
Результат boolean

getForm() публичный статический Метод

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
Результат string The form HTML markup

getFrontendModule() публичный статический Метод

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
Результат string The module HTML markup

getImage() защищенный Метод

Resize an image and crop it if necessary
Устаревший: 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
Результат string | null The image path or null

getPageDetails() публичный статический Метод

Get the details of a page including inherited parameters
Устаревший: 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
Результат PageModel The page model or null

getPageSections() публичный статический Метод

Return all page sections as array
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. See https://github.com/contao/core/issues/4693.
public static getPageSections ( ) : array
Результат array An array of active page sections

getPageStatusIcon() публичный статический Метод

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
Результат string The status icon name

getParentEntries() защищенный Метод

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
Результат string A string that can be used in a log message

getParentRecords() защищенный Метод

Return the IDs of all parent records of a particular record
Устаревший: 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
Результат array An array of parent record IDs

getSpellcheckerString() защищенный Метод

Return the languages for the TinyMCE spellchecker
protected getSpellcheckerString ( ) : string
Результат string The TinyMCE spellchecker language string

getTemplate() публичный статический Метод

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
Результат string The path to the template file

getTemplateGroup() публичный статический Метод

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_")
Результат array An array of template names

getTheme() публичный статический Метод

Return the current theme as string
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Backend::getTheme() instead.
public static getTheme ( ) : string
Результат string The name of the theme

isVisibleElement() публичный статический Метод

Check whether an element is visible in the front end
public static isVisibleElement ( Model $objElement ) : boolean
$objElement Model The element model
Результат boolean True if the element is visible

loadDataContainer() публичный статический Метод

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() публичный статический Метод

Return a "checked" attribute if the option is checked
Устаревший: 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
Результат string The attribute or an empty string

optionSelected() публичный статический Метод

Return a "selected" attribute if the option is selected
Устаревший: 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
Результат string The attribute or an empty string

parseSimpleTokens() защищенный Метод

Parse simple tokens that can be used to personalize newsletters
Устаревший: 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
Результат string The text with the replaced tokens

prepareForWidget() защищенный Метод

Convert a DCA file configuration to be used with widgets
Устаревший: 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
Результат array An array that can be passed to a widget

printArticleAsPdf() защищенный Метод

Print an article as PDF and stream it to the browser
Устаревший: 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() публичный статический Метод

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() защищенный Метод

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
Результат string The URL of the target page

reload() публичный статический Метод

Reload the current page
public static reload ( )

removeOldFeeds() защищенный Метод

Remove old XML files from the share directory
Устаревший: 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
Результат array An array of old XML files

replaceDynamicScriptTags() публичный статический Метод

Replace the dynamic script tags (see #4203)
public static replaceDynamicScriptTags ( string $strBuffer ) : string
$strBuffer string The string with the tags to be replaced
Результат string The string with the replaced tags

replaceInsertTags() публичный статический Метод

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
Результат string The text with the replaced tags

replaceOldBePaths() защищенный статический Метод

Replace the old back end paths
protected static replaceOldBePaths ( string $strContext ) : string
$strContext string The context
Результат string The modified context

resizeImage() защищенный Метод

Resize an image and crop it if necessary
Устаревший: 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
Результат boolean True if the image has been resized correctly

restoreBasicEntities() публичный статический Метод

Restore basic entities
Устаревший: 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
Результат string The string with the original entities

sendFileToBrowser() публичный статический Метод

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

setStaticUrls() публичный статический Метод

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