Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Load data batch

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.

by Francois Zaninotto on 2006-05-20, tagged batch  data  propel 

Comments on this snippet

gravatar icon
#1 Dustin Whittle on 2006-05-22 at 02:43

To remove database contents before hand add:

$data->setDeleteCurrentData(true);

gravatar icon
#2 Francois Zaninotto on 2006-05-22 at 09:32

The data is removed by default. It is if you don't want to remove data that you have to specify:

$data->setDeleteCurrentData(false);

before the call to -&gt;loadData().

gravatar icon
#3 Francois Zaninotto on 2006-10-16 at 06:51

This snippet has been included into the symfony code since 0.8.

$ symfony propel-load-data myapp
gravatar icon
#4 excessive demon on 2007-04-04 at 09:16

What code changes do we need to make if we are working with multiple databases, on database model?

You need to create an account or log in to post a comment or rate this snippet.