1. Go to this page and download the library: Download fiedsch/contao-components library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fiedsch / contao-components example snippets
$GLOBALS['TL_DCA']['tl_member']['fields']['json_data'] = [
'inputType' => 'jsonWidget',
'label' => &$GLOBALS['TL_LANG']['tl_member']['json_data'],
'eval' => ['tl_style'=>'long', 'decodeEntities'=>true, 'allowHtml'=>true ],
'sql' => "blob NULL",
];
// Add json_data to $GLOBALS['TL_DCA']['tl_member']['palettes']['default']
// where ever you like
// models/ExtendedMemberModel.php
namespace Contao;
class ExtendedMemberModel extends \MemberModel
{
// let __set() and __get take care of the JSON data
use \Fiedsch\JsonGetterSetterTrait;
/**
* The column name we selected for the `jsonWidget` in the example above
* @var string
*/
protected static $strJsonColumn = 'json_data';
}
$member = \ExtendedMemberModel::findById(42);
// access fields columns created by contao's default DCA
printf("read member %s %s\n", $member->firstname, $member->lastname);
// access a field stored in our JSON data column
printf("transparently accessing a field from the JSON data ... '%s'\n", $member->whatever);
// set values and store in database
$member->a_key_for_a_scalar_value = "fourtytwo";
$member->key_for_an_array = ['an','array','containing','some','strings'];
$member->save();