yii\test\ActiveFixture::getData PHP 메소드

getData() 보호된 메소드

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.
protected getData ( ) : array
리턴 array the data rows to be inserted into the database table.
    protected function getData()
    {
        if ($this->dataFile === null) {
            $class = new \ReflectionClass($this);
            $dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php';
            return is_file($dataFile) ? require $dataFile : [];
        } else {
            return parent::getData();
        }
    }

Usage Example

예제 #1
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();
     }
 }