¿Puedo usar variables definidas en parameters.ini en validación o enrutamiento?

I was wondering if I could define some variables in parameters.ini and use them in various yml files like validation, routing, etc?

¿Es esto posible?

preguntado el 02 de febrero de 12 a las 10:02

2 Respuestas

For any of Symfony2's YAML files that support imports, puede utilizar la siguiente sintaxis:

imports:
    - { resource: parameters.yml }

Of course, this requires a bit of upgrading since parameters.yml is currently Symfony 2.1.x and 2.0.x still uses parameters.ini.

You would be better off passing variables around using service parameters. See esta sección of the documentation on the service container.

Respondido 02 Feb 12, 19:02

It's up to you to choose the format you want. yml FileLoader is supported since the beginning. It's the symfony-standard distribution that changed his default format. - Florian Klein

@Florian: Half true, if you try to use the YamlLoader for parameters.*, you will get errors from the SensioGeneratorBundle as it relies on parameters.ini. An easy fix by upgrading that bundle which is what I was referring to. - Puerro

The configuration of validator and routing differs in its implementation.

DependencyInjection configuration files support the imports palabra clave.

Routing configuration files support the resources palabra clave.

Validator configuration files do no support import.

Translation configuration files do no support import.

Respondido 02 Feb 12, 21:02

So I guess I ca not do it. I have a regular expression that is repeated multiple times throughput routing, security and validation. It would be great if I could use one source so that I would not have to change it everywhere when change is due - DavidW

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.