Where To Put Arrays For Common Data Storage In Symfony Where To Put Arrays For Common Data Storage In Symfony symfony symfony

Where To Put Arrays For Common Data Storage In Symfony


If you want to use this data with other Entities, for example State would be connected to Adress object, I would stick with Entities, because it makes relations easier to implement and work with (I assume you using some kind of ORM e.g. Doctrine).

If you don't want to use this data with other entities, maybe you would like to hardcode them into all the templates somehow. http://symfony.com/doc/current/cookbook/templating/global_variables.html (I assumed you are using Twig).

A similar question was answered here:Where to define static array related to an entity in symfony2 ?


It depends. I would opt by having that kind of data in the database. Suppose you in the future would have a back-office that update data.

Or you could use config files. For example, in yml format, arrays is easy to define.


Just like @foxtrot said, any data that is changeable should be stored in the database, just so you do not have to edit any code when a change occurs.

Firstly, I would create the Entity for the common data, and then I would use Fixtures to generate the entries in the database when you deploy your code.

This way, you allow later editing through either forms or phpMyAdmin, but you also get to write the default values into a PHP class so you don't have to manually enter all of them into the database.

See Symfony - DoctrineFixturesBundle