I have following .env
file:
VAR=8888
I want to use this variable from .env
file in the constraint config file. So I do this:
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="App\Entity">
<property name="page">
<constraint name="EqualTo">
<option name="value">%env(string:VAR)%</option>
</constraint>
</property>
</class>
</constraint-mapping>
But the env value is not interpreted. It just prints sth like this: \"%env(string:VAR)%\"
Also I have tried first to set parameter in config.yaml
, like this:
parameters:
var: '%env(resolve:VAR)%'
And then try to use like this:
...
<constraint name="EqualTo">
<option name="value">%var%</option>
</constraint>
...
But it also does not work.
I am using php v. 8.1 with symfony v. 6.1 I have tried to remove cache and restart docker containers but it didn't help :(