PHP code example of fiedsch / contao-components

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';

}

// config/config.php
$GLOBALS['TL_MODELS']['tl_member'] = 'Contao\ExtendedMemberModel';

// config/autoload.php
// ...
ClassLoader::addClasses(
    [
        // ...
        'Contao\ExtendedMemberModel' => 'system/modules/your_extension/models/ExtendedMemberModel.php',
        // ...
    ]
);
// ...

$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();

use Fiedsch\YamlConfigHelper;

$defaults = [
    'messages' => [
                    'de' => 'Guten Tag',
                    'fr' => 'Bonjour',
                    'en' => 'Hello',
                   ]
            ];
$config = new YamlConfigHelper('files/config/config.yaml', $defaults);

$config->getEntry('data.messages.de'); // 'Guten Tag'
$config->getEntry('data.messages.es'); // null

$config->getEntry('data.messages.de'); // 'Guten Morgen'
$config->getEntry('data.messages.es'); // null

$config->getEntry('data.messages.es'); // null
$config->getEntry('data.messages.es', "¡buenos días!"); // "¡buenos días!"

$config->getEntry('data.messages');
/*
object(stdClass)#233 (3) {
  ["de"]=>
  string(12) "Guten Morgen"
  ["fr"]=>
  string(7) "Bonjour"
  ["en"]=>
  string(12) "Good Morning"
}
*/

(array)$config->getEntry('data.messages');
/*
array(3) {
  ["de"]=>
  string(12) "Guten Morgen"
  ["fr"]=>
  string(7) "Bonjour"
  ["en"]=>
  string(12) "Good Morning"
}
*/

$config = new YamlConfigHelper('files/sompe/path/to/a/file.yaml');