Is a tool which provides an ability to use fixtures with Yii framework.
- All attributes you want to fill via fixtures data, must be defined with
safe
validation rule (rules()
method); - Don't forget configure
tablePrefix
option fordb
connection definition; - Your tables will be purged when you loading fixtures;
-
Download extension and place it in
extensions
directory; -
Create file
fixtures.php
, with content, what will be looks like this:
<?php
return array(
'ModelClassName' => array(
'modelInstanceId' => array(
'field1' => 'value1',
'field2' => 'value2',
...
),
...
),
...
);
- Make sure that you have configured database for console application. Add the following code to your console config:
...
'commandMap' => array(
'fixtures' => array(
'class' => 'ext.fixture_manager.EDbFixtureManager', // import class of console command
'pathToFixtures' => '/path/to/fixtures.php', // pass the path to your fixtures file
'modelsFolder' => 'application.models.*', // specify the folder where your models classes lays
),
),
...
NOTE. If you have a multiple models folder you can specify modelsFolder
as an array.
E.g. 'modelsFolder' => array('application.models.*', 'application.modules.user.models.*') ,
- Run command:
php path/to/yiic fixtures load
;