Contao Methoden

Eine Referenz zu allen Verfügbaren Contao 3 Methoden findet sich auf api.contao.org

 

Datenbankzugriff

/*
 * Get data entry by id
 * @return object
 */
$pageObj = \PageModel::findByPk(int $id);
$imgObj = \FilesModel::findByPk(int $id);

/*
 * Get Model Object Array
 * @return array
 */
$dataArray = $modelObj->getResult()->fetchAllAssoc();

 

Bilder verarbeiten

// contao 3.0.1 +

/*
 * get image source path by id
 * @retung array
 */
$imageSrc = \FilesModel::findByPk($ID)->path;

/*
 * resize original image
 * @retung string
 */
\Image::resize($imageURL, $width, $height, $mode);

/*
 * resize copy
 * @retung string
 */
\Image::get($imageURL, $width, $height, $mode, [$target], [$force]);

/*
 * create image tag
 * @retung string
 */
\Image::getHtml($src, [$alt], [$attributes]);
// deprecated version
$this->generateImage($this->getImage('/path/to/image.jpg', $with, $height, $croping), $altTag)

 

Werte verarbeiten

// Create margin/padding HTML from inputUnit form field
static::generateMargin(deserialize($this->my_table_col), 'margin');

 

// Get page object by ID
$pageObj = \PageModel::findByPk(3);

// get page object by alias
$pageObjAlias = \PageModel::findByAlias('academy');

// Get page title
$pageObj->title;

// Get frontend URL by ID
Controller::generateFrontendUrl($pageObj->row());

// Check if current page is homepage of this root
if(\PageModel::findFirstPublishedRootByHostAndLanguage($objPage->domain, $objPage->language)->id == $objPage->pid){};

 

Browserinformationen

// Get user agent info as array
$userAgent = \Environment::get('agent');

 

Mitteilungen anzeigen

// show red error message box
\Message::addError($strMessage);

// show confirmation
\Message::addConfirmation($strMessage);

// add new message
\Message::addNew($strMessage);

// add blue info message
\Message::addInfo($strMessage);

// add message that doesn't need to be parsed
\Message::addRaw($htmlStrMessage);

 

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht.