Reputation: 5245
I need to create custom array and make it global visible, so controllers can use it later. I read about services, but making special class only for storing array sound like a bit exaggeration to me. Is there any other way to do this?
Array is immutable, two-dimensional, like:
$races = array(
'human' => array(
1 => 'tribe1',
2 => 'tribe2'
),
'dwarf' => array(
1 => 'drarftribe1'
)
);
So its very simple structure.
Upvotes: 0
Views: 93
Reputation: 22797
Then just create a Races
class, and namespace it wherever you want:
/src/Acme/YourBundle/Races.php
<?php
namespace Acme\YourBundle;
class Races
{
static $yourData;
}
Whenever you need, refer to Acme\YourBundle\Races::$yourData
.
Upvotes: 1
Reputation: 488
class GlobalArray {
static public $data = array();
}
Access:
$var = GlobalArray::$data[index];
Upvotes: 1