keep const value in Symfony

Here is the problem:

I have been trying to keep the value of a const variable if is defined in app.php in Symfony. This is my code.

The design of the app was made it like this. with a constant that indicates what type of system to start.
This is my code.

if(!defined("ENTORNO")) {
define("ENTORNO",2,true);
} 

i’m using “true” to redefine the const value. I have a REST service to redefine the const variable. Like this.

     * @RestGet("/api/VersionSistema/{id}", name="VersionSistemas")
 */
public function VersionSistemas($id)
{
    try {
        define("ENTORNO",$id);
        return new View(Response::HTTP_OK);
    } catch (Exception $e) {
        return new View($e->getMessage(), Response::HTTP_BAD_REQUEST);
    }
}

My problem is that in each request the variable loses its value and is reinitialized. So ┬┐how could I always keep the value with which I redefined the variable?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *