Jakoss
Jakoss

Reputation: 5245

Custom structure globally visible for whole symfony2 application

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

Answers (2)

moonwave99
moonwave99

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

S3Mi
S3Mi

Reputation: 488

class GlobalArray {
    static public $data = array();
}

Access:

$var = GlobalArray::$data[index];

Upvotes: 1

Related Questions