Where and how to define a constant in Symfony?

I have several of my own constants in symfony and need to make them available throughout the application, where are they best defined?

I tried in the directory to myapps\config\config.phpdefine my constant like this:

sfConfig::set('aaa', 'mya');

But when I tried to access the constant in myapps\apps\frontend\modules\login\actions\actions.class.phpusing this command

sfConfig::get('aaa')

I just get zero, indicating that it is not defined.

How and where to define a symfony constant so that it is available throughout the project?

+3
source share
3 answers

This is how I solved the problem:

Put the following in mine myapp/apps/frontend/config/app.yml:

all:
  .app_set:
    bpobackend:       me
    bpoRedirectScreen:    allow

Then in the action module call var_dump to check the value

var_dump(sfConfig::get('app_bpobackend'));
+3
source

, symfony 1.0 symfony 1.1 1.2. config.php 1.1. . . (1_2 ( , ) URL-).

+2

I tried adding a constant to config.php in Symfony 1.0 ..

So, if you want to add constant variables to config.php, then

sfConfig::add(array('SF_DEFAULT_DATEFORMAT' => 'dd-MM-yyyy'));

This is the code in which I define the date format named "SF_DEFAULT_DATEFORMAT" ...

So you can try with this ...

0
source

Source: https://habr.com/ru/post/1704373/


All Articles