How to access a database from the configure method of a symfony task

You can create a symfony “task” by expanding sfBaseTask; See http://www.symfony-project.org/cookbook/1_1/en/tasks for more details .

However, I do not see how to configure the database connection in the section configure. I want to do this so that I can have the property to detailedDescriptionshow some parameters that are defined only in the database.

What is the best way to do this?

+3
source share
2 answers

If you look at the way symfony creates a custom task skeleton ( ./symfony generate:task yourTaskName), you will see the code that looks like inside the execution function:

protected function execute([..])
{
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
[..]

, , , ( database.yml schema.yml, ), , :

protected function configure()
{
         $databaseManager = new sfDatabaseManager(sfProjectConfiguration::getApplicationConfiguration('frontend'‌​, 'prod', true));
         $connection = $databaseManager->getDatabase("the_name_of_your_connection")->getConnection();  
[..]

, :

    $myItem = Doctrine_Core::getTable('item')->find(14);
    echo $myItem->getId();
+1

Doctrine, - php. /PROJECT/lib/model/doctrine/MODEL _NAMETable.class.php

MVC!

, : Doctrine_Core::getTable('TABLE_NAME')->miNewMethod($params-if-any);

, !

+1

All Articles