Either [[modelClass]] or [[tableName]] must be set. You should also provide fixture data in the file specified by [[dataFile]] or overriding ActiveFixture::getData if you want to use code to generate the fixture data. When the fixture is being loaded, it will first call ActiveFixture::resetTable to remove any existing data in the table. It will then populate the table with the data returned by ActiveFixture::getData. After the fixture is loaded, you can access the loaded data via the [[data]] property. If you set [[modelClass]], you will also be able to retrieve an instance of [[modelClass]] with the populated data via [[getModel()]]. For more details and usage information on ActiveFixture, see the guide article on fixtures.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends BaseActiveFixture
 public function unload()
 {
     $table = $this->getTableSchema();
     foreach ($this->getData() as $alias => $row) {
         \Yii::$app->db->createCommand()->delete($table->fullName, $row)->execute();
     }
     parent::unload();
 }
Beispiel #2
0
 /**
  * Returns the fixture data.
  *
  * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
  * The file should return an array of data rows (column name => column value), each corresponding to a row in the table.
  *
  * If the data file does not exist, an empty array will be returned.
  *
  * @return array the data rows to be inserted into the database table.
  */
 protected function getData()
 {
     if ($this->dataFile === null) {
         $class = new \ReflectionClass($this);
         $dataFile = $this->dirData($class) . '/' . str_replace('_', '/', $this->getTableSchema()->fullName) . '.php';
         return is_file($dataFile) ? require $dataFile : parent::getData();
     } else {
         return parent::getData();
     }
 }
Beispiel #3
0
 public function load()
 {
     parent::load();
     $installer = Yii::$app->rbacInstaller;
     $installer->assign();
 }
 /**
  * @inheritdoc
  */
 public function unload()
 {
     parent::unload();
     $this->resetTable();
 }
Beispiel #5
0
 public function __construct($config = [])
 {
     $this->tableName = 'user';
     parent::__construct($config);
 }
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->dataFile = __DIR__ . '/data/records.php';
 }