MageWork

Back to home

Data assignment

You can simply pass data to any object or template with the configuration file: packages/acme/etc/config.php

The key default provides data to all objects.

<?php

$config = [
    'acme' => [
        'default' => [
            'default' => [
                'scope' => 'I\'m available everywhere in the "acme" package',
            ],
        ],
        Core_Block::TYPE => [
            'default' => [
                'scope' => 'I\'m available in all blocks of the "acme" package',
            ],
            'banner' => [
                'scope' => 'I\'m available in the block "banner" of the "acme" package',
            ],
        ],
    ],
];

The data will be available in class or template file with the getData method or the magic getter:

<?php

$this->getData('scope');
// or
$this->getScope();

Use global configuration file to set data to packages and objects according the environment: etc/config.{MW_ENVIRONMENT}.php

<?php

$config = [
    'default' => [
        'default' => [
            'default' => [
                 'scope' => 'I\'m available everywhere in all packages for the current environment',
            ],
        ],
        Core_Page::TYPE => [
            'default' => [
                'scope' => 'I\'m available in all pages of all packages for the current environment',
            ],
        ],
        Core_Block::TYPE => [
            'banner' => [
                'scope' => 'I\'m available in the block "banner" of all packages for the current environment',
            ],
        ],
    ],
];

A "default" value will be overridden by the specified package, type or identifier.

Overload hierarchy:

  1. default.default.default
  2. default.default.{identifier}
  3. default.{type}.default
  4. default.{type}.{identifier}
  5. {package}.default.default
  6. {package}.default.{identifier}
  7. {package}.{type}.default
  8. {package}.{type}.{identifier}