Controllers are easy, but views cannot access static properties by default.
You'd probably want to set it up as a service, but keep in mind that only objects can be services.
// Globals.php
class Globals {
protected static $_globals = [];
public function __construct(array $globals=[]) {
self::$_globals = array_merge(self::$_globals, $globals);
}
public function set($name, $value) {
self::$_globals[$name] = $value;
}
public function get($name) {
return self::$_globals[$name];
}
}
// services.php
$di->set('globals', function() {
return new Globals();
});
// controller
public function someAction() {
$this->globals->set('someName') = array('foo'=>'bar');
$foo = $this->globals->get('someName')['foo'];
}
// view
{{ globals.get('someName')['foo'] }}
Don't forget to register the class in the loader!