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
コード例 #1
0
 public function unload()
 {
     $table = $this->getTableSchema();
     foreach ($this->getData() as $alias => $row) {
         \Yii::$app->db->createCommand()->delete($table->fullName, $row)->execute();
     }
     parent::unload();
 }
コード例 #2
0
ファイル: GxActiveFixture.php プロジェクト: dlds/yii2-giixer
 /**
  * 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();
     }
 }
コード例 #3
0
ファイル: UserFixture.php プロジェクト: frostiks25/rzwebsys7
 public function load()
 {
     parent::load();
     $installer = Yii::$app->rbacInstaller;
     $installer->assign();
 }
コード例 #4
0
 /**
  * @inheritdoc
  */
 public function unload()
 {
     parent::unload();
     $this->resetTable();
 }
コード例 #5
0
ファイル: UserFixture.php プロジェクト: iw-reload/iw
 public function __construct($config = [])
 {
     $this->tableName = 'user';
     parent::__construct($config);
 }
コード例 #6
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->dataFile = __DIR__ . '/data/records.php';
 }