* @copyright (c), Thread */ class ActionColumn extends Column { /** * @var array */ public $contentOptions = [ 'class' => 'text-center', ]; /** * @var array */ public $headerOptions = [ 'class' => 'text-center' ]; /** * @var string|array|boll|Closure */ public $updateLink; /** * @var string|array|boll|Closure */ public $deleteLink; /** * @var string */ public $header = 'Actions'; /** * @inheritdoc */ protected function renderDataCellContent($model, $key, $index) { $updateLink = ($this->getUpdateLink($model) !== false) ? Html::a(' ', $this->getUpdateLink($model), ['class' => 'btn btn-success btn-s']) : ''; $deleteLink = ($this->getDeleteLink($model) !== false) ? Html::a(' ', $this->getDeleteLink($model), ['class' => 'btn btn-danger btn-s']) : ''; return '
' . $updateLink . '     ' . $deleteLink . '
'; } /** * @param $model * @return array|bool|mixed */ protected function getUpdateLink($model) { if ($this->updateLink === false) { return false; } if (!empty($this->updateLink)) { if ($this->updateLink instanceof \Closure) { $f = $this->updateLink; return $f($model); } else { $r = ['update']; foreach ($this->updateLink as $data) { $r[$data] = $model->$data; } return $r; } } else { return ['update', 'id' => $model->id]; } } /** * @param $model * @return array|bool|mixed */ protected function getDeleteLink($model) { if ($this->deleteLink === false) { return false; } if (!empty($this->deleteLink)) { if ($this->deleteLink instanceof \Closure) { $f = $this->deleteLink; return $f($model); } else { $r = ['intrash']; foreach ($this->deleteLink as $data) { $r[$data] = $model->$data; } return $r; } } else { return ['intrash', 'id' => $model->id]; } } /** * Renders the header cell content. * The default implementation simply renders [[header]]. * This method may be overridden to customize the rendering of the header cell. * @return string the rendering result */ protected function renderHeaderCellContent() { return trim($this->header) !== '' ? \Yii::t('app', $this->header) : $this->getHeaderCellLabel(); } }