Monday, August 19, 2013

How to use Contao Model arrOptions

just a quick snippet, feel free to comment if you need more details

<?php

$columns = $values = array();

$columns[] = 'published = ?';
$values[] = '1';

$arrOptions = array(
'column' => $columns,
'value' => $values,
'offset' => 0,
'limit' => 10,
'return' => 'Collection',
'uncached' => true
);
// using getModelClassFromTable is a nice way to take refactoring in mind
$model = $this->getModelClassFromTable('tl_page');
$collection = $model::findAll($arrOptions);

?>

Wednesday, April 24, 2013

Contao 2.x Hooks Tutorial (processFormData)

Contao Hooks are functions that get triggered on certain events. For a list of available hooks take a look at the Contao Documentation.

Here is a quick tutorial on how to setup a hook for processing form data entered by members in your website.

Sunday, April 7, 2013

Contao 3 – redirect to a frontend url from page alias

<?php

class MyModule extends \Module {


protected function compile() {

$page_alias = 'my-page-alias';
$arrPage = \PageModel::findPublishedByIdOrAlias($page_alias)->current()->row();

$strUrl = $this->generateFrontendUrl($arrPage, '/additionalquerystring/vars');

$this->redirect($strUrl);



}

}

Friday, April 5, 2013

Contao 3 – Generate a form inside a custom template

 

<?php

/**
* STEP #1 (just in case you want to get the form by its alias)
* get the form id from its alias
* if you have the form id you can skip to step #2
*/
$objModel = \FormModel::findByAlias($form_alias);
$form_id = $objModel->id;


/**
* STEP #2
* generate the configuration object
**/

$objContent = new stdClass();
$objContent->form = $form_id;

/**
* STEP #3
* generate the form object
**/
$objForm = new \Form($objContent);
?>


<?php
/**
* STEP #4
* display the Form
**/
?>
<?php echo $objForm->generate(); ?>

Saturday, February 2, 2013

How to manually update newsletter member’s field in Contao 3

 

// id of the member we wish to update

$memberId = 2;

// array of newsletter channel's id

$arrNewsletter = array("1");

$objMember = \MemberModel::findByPk($memberId);

// first sync the newsletter

$objNewsletter = new \Newsletter();

$objNewsletter->synchronize($arrNewsletter, $objMember)

// after syncing update the member model

$objMember->newsletter = $arrNewsletter;
$objMember->save();

Tuesday, November 29, 2011

Quick tip: easy writing of informative fields with ZedSeriesUi

The Data Container Array (a.k.a. dca) of Contao cms allows to define custom fields through the input_field_callback entry. A common usage scenario is providing informative contents to your users. This can be accomplished easily using the ZedSeriesUi class (that is included in ZedSeries Library for Contao cms).

Define your informative field as input_field_callback:

<?php

$GLOBALS['TL_DCA']['tl_dummy']['fields']['my_info_field'] = array(
'input_field_callback' => array('tl_dummy', 'myInfoField')
);

?>


Write your callback


<?php 

class tl_dummy {

public function myInfoField($dc) {
$ui = new ZedSeriesUi();
return $ui->ifcMessage('My content', 'zsui_info');
}

}

This will output a nice informative message



Feel free to comment below if you have further questions.

Friday, November 25, 2011

How to create a custom insert tags for Contao

The Contao cms supports dynamic content integration through the so called "insert-tags". Contao has a lot of built in "insert-tags" but sometimes when writing custom extensions may be the need to create a custom one.