![]() |
|
Snippets |
|
Create a batch/load_data.php script with:
<?php define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', true); require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); // initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $data = new sfPropelData(); $data->loadData(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures'); ?>
Call it with:
$ cd batch
$ php load_data.php
It will load the data contained in all the .yml files of the data/fixtures/ directory.
Comments on this snippet
To remove database contents before hand add:
$data->setDeleteCurrentData(true);
The data is removed by default. It is if you don't want to remove data that you have to specify:
before the call to
->loadData().This snippet has been included into the symfony code since 0.8.
What code changes do we need to make if we are working with multiple databases, on database model?