Yii 1.1: datagenerationbehavior

Automatically generate some random data sets for a specified model.
5 followers

This Behavior lets you automatically generate some random data into your database. A random number will be generated for int fields. String fields will be filled with lorem ipsum Text.

Requirements

Developed with Yii 1.1.13. Should work with any 1.1 Version of Yii.

Usage

  1. Extract the DataGenerationBehavior.php into your components/ folder

  2. Register the behavior on the model where you want to generate demo data :

public function behaviors() {
    return array(
        'DataGenerationBehavior' => array(
        'class' => 'application.components.DataGenerationBehavior',
    )
);
}
  1. Make sure to be in YII_DEBUG mode and call $model->generateDemoData(); somewhere.

  2. You can configure 'count', 'intMin', 'intMax' or the 'lorem' attribute.

count: number of data sets to be generated, default 10 intMin: minimal number generated for int fields, default 0 maxMin: minimal number generated for int fields, default 1000 lorem: the text generated, default is the lorem ipsum default text.

TODO:

  • At the moment we do not obey relations! Would be cool if a random number would be generated only for valid related objects! (for example, a column user_id that links to a specified user would generate a random number between all available users)

Total 1 comment

#12557 report it
schmunk at 2013/03/28 02:35pm
Repo?

Is it on github?

Leave a comment

Please to leave your comment.

Create extension