Edhrendal
Edhrendal

Reputation: 672

Symfony 1: Get app config parameters

I'm writting tests and task for a new app for an application and I need to access to the "app config parameters" of this new app defined in /apps/mynewapp/config/app.yml. I thought it will be as easy as written in the Symfony doc, but it seems I've forgotten something.

When I get my config: $actions = sfConfig::get("app_actions") it is NULL. I thought the config name is wrong, but when I get all the config parameters available with sfConfig::getAll(), I don't have my app config parameters.

Maybe I've forgotten to include my /apps/mynewapp/config/app.yml?

There is the content of my file:

all:
    .array:
        actions:
            bind_destroy: BindDestroyAction
            bind_subscribe: BindSubscriptionAction
        messages:
            bind_destroy: BindDestroyMessage
            bind_subscribe: BindSubscriptionMessage

And there is how I try to access to my parameters in /apps/mynewapp/lib/GRM/GRMSender.class.php:

class GRMSender
{
    private $actionClassNames;
    private $messageClassNames;

    public function __construct()
    {
        $this->actionClassNames = sfConfig::get("app_actions");
        $this->messageClassNames = sfConfig::get("app_messages");
    }
}

The class has already been autoloaded and I'm able to instantiate the class in my unit test scripts.

Thank you for your help.

EDIT

The problem is about my tests (in /test/unit) and my tasks (in /lib/task). I have to use what I did in my application "mynewapp". I did some things :

$configMynewapp = ProjectConfiguration::getApplicationConfiguration("mynewapp", sfConfig::get("sf_environment"), true);

There must be better ways to get mynewapp config parameters in tasks and in tests. In mynewapp files (controller, lib, etc.) it's ok.

Upvotes: 1

Views: 1115

Answers (1)

davidvegacl
davidvegacl

Reputation: 151

Try to do this:

/apps/mynewapp/config/app.yml

all:
  actions:
    bind_destroy: BindDestroyAction
    bind_subscribe: BindSubscriptionAction
  messages:
    bind_destroy: BindDestroyMessage
    bind_subscribe: BindSubscriptionMessage

Then you can get:

$actions = sfConfig::get('app_actions');

It will return:

$actions => array(
  'bind_destroy' => 'BindDestroyAction',
  'bind_subscribe' => 'BindSubscriptionAction'
)

Anyway, you can access one of them directly:

$action = sfConfig::get('app_actions_bind_destroy')
$action => 'BindDestroyAction'

Upvotes: 1

Related Questions