yii\grid\GridView::createDataColumn PHP Method

createDataColumn() protected method

Creates a DataColumn object based on a string in the format of "attribute:format:label".
protected createDataColumn ( string $text ) : DataColumn
$text string the column specification string
return DataColumn the column instance
    protected function createDataColumn($text)
    {
        if (!preg_match('/^([^:]+)(:(\\w*))?(:(.*))?$/', $text, $matches)) {
            throw new InvalidConfigException('The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"');
        }
        return Yii::createObject(['class' => $this->dataColumnClass ?: DataColumn::className(), 'grid' => $this, 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', 'label' => isset($matches[5]) ? $matches[5] : null]);
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function createDataColumn($text)
 {
     $column = static::column($text);
     if (is_array($column)) {
         $column['attribute'] = $column['attribute'] ?: $text;
         return $this->createColumnObject($column);
     }
     return parent::createDataColumn($text);
 }