0 follower

Final Class Yiisoft\Yii\DataView\GridView\Column\ActionColumn

InheritanceYiisoft\Yii\DataView\GridView\Column\ActionColumn
ImplementsYiisoft\Yii\DataView\GridView\Column\ColumnInterface

ActionColumn is a column for the {@see GridView} widget that displays buttons for viewing and manipulating the items.

// Basic usage with default view, update, and delete buttons
$column = new ActionColumn();

// Custom URL creator
$column = new ActionColumn(
    urlCreator: static fn(string $action, DataContext $context): string => "/$action/{$context->data->id},
);

// Custom buttons using ActionButton instances
$column = new ActionColumn(
    buttons: [
        'view' => new ActionButton(
            content: '🔎',
            url: static fn(array|object $data, DataContext $context): string => "/view/$data->id",
            title: 'View',
        ),
        'delete' => new ActionButton(
            content: '❌',
            url: static fn(array|object $data, DataContext $context): string => "/delete/$data->id",
            title: 'Delete',
            attributes: ['onclick' => "return confirm('Are you sure?')"],
        ),
    ],
);

// Custom buttons using callables
$column = new ActionColumn(
    buttons: [
        'approve' => static fn(string $url): string => Html::a('Approve', $url, ['class' => 'btn btn-success']),
    ],
    template: '{approve}',
);

// Conditionally visible buttons
$column = new ActionColumn(
    visibleButtons: [
        'delete' => static fn(array|object $data, DataContext $context): bool => $data['deletable'],
    ],
);

Property Details

Hide inherited properties

$after public property
public ?string $after null
$before public property
public ?string $before null
$bodyAttributes public property
public array $bodyAttributes = []
$buttons public property
public ?array $buttons null
$columnAttributes public property
$content public property
public mixed $content null
$footer public property
public ?string $footer null
$footerAttributes public property
$header public property
public ?string $header null
$headerAttributes public property
$template public property
public ?string $template null
$urlConfig public property
public mixed $urlConfig null
$visibleButtons public property
public ?array $visibleButtons null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|null $template null, string|null $before null, string|null $after null, mixed $urlConfig null, callable|null $urlCreator null, string|null $header null, string|null $footer null, mixed $content null, array|null $buttons null, array|null $visibleButtons null, array $columnAttributes = [], array $headerAttributes = [], array $bodyAttributes = [], array $footerAttributes = [], boolean $visible true )
$template string|null

The template used for composing each cell in the action column.

$before string|null

Content to be prepended to the action column content.

$after string|null

Content to be appended to the action column content.

$urlConfig mixed

URL configuration for generating button URLs.

$urlCreator callable|null

A callback that creates a button URL using the specified data information.

$header string|null

The header cell content.

$footer string|null

The footer cell content.

$content mixed

The content to be rendered in each data cell.

$buttons array|null

Array of buttons. Keys are button names. Values are either instances of {@see \Yiisoft\Yii\DataView\GridView\Column\ActionButton} or a callable with the following signature: function(string $url, DataContext $context): string.

$visibleButtons array|null

Array of button visibility rules.

$columnAttributes array

HTML attributes for the column cells.

$headerAttributes array

HTML attributes for the header cell.

$bodyAttributes array

HTML attributes for the body cells.

$footerAttributes array

HTML attributes for the footer cell.

$visible boolean

Whether the column is visible.

                public function __construct(
    public readonly ?string $template = null,
    public readonly ?string $before = null,
    public readonly ?string $after = null,
    public readonly mixed $urlConfig = null,
    ?callable $urlCreator = null,
    public readonly ?string $header = null,
    public readonly ?string $footer = null,
    public readonly mixed $content = null,
    public readonly ?array $buttons = null,
    public readonly ?array $visibleButtons = null,
    public readonly array $columnAttributes = [],
    public readonly array $headerAttributes = [],
    public readonly array $bodyAttributes = [],
    public readonly array $footerAttributes = [],
    private readonly bool $visible = true,
) {
    $this->urlCreator = $urlCreator;
}

            
getRenderer() public method

public string getRenderer ( )

                public function getRenderer(): string
{
    return ActionColumnRenderer::class;
}

            
getUrlCreator() public method

Get the URL creator callback.

public callable|null getUrlCreator ( )
return callable|null

The URL creator callback.

                public function getUrlCreator(): ?callable
{
    return $this->urlCreator;
}

            
isVisible() public method

public boolean isVisible ( )

                public function isVisible(): bool
{
    return $this->visible;
}