yii\test\BaseActiveFixture::getData PHP Method

getData() protected method

The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. The file should return the data array that will be stored in [[data]] after inserting into the database.
protected getData ( ) : array
return array the data to be put into the database
    protected function getData()
    {
        if ($this->dataFile === false || $this->dataFile === null) {
            return [];
        }
        $dataFile = Yii::getAlias($this->dataFile);
        if (is_file($dataFile)) {
            return require $dataFile;
        } else {
            throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}");
        }
    }

Usage Example

 /**
  * 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 index.
  *
  * If the data file does not exist, an empty array will be returned.
  *
  * @return array the data rows to be inserted into the database index.
  */
 protected function getData()
 {
     if ($this->dataFile === null) {
         $class = new \ReflectionClass($this);
         $dataFile = dirname($class->getFileName()) . "/data/{$this->index}/{$this->type}.php";
         return is_file($dataFile) ? require $dataFile : [];
     } else {
         return parent::getData();
     }
 }
All Usage Examples Of yii\test\BaseActiveFixture::getData