btn_active() table()
An Active / Inactive toggle in each row, showing the state of the row field named after the button (active).
table()->btn_active($name = '', $link = '', $extra = [])Options
| Option | Meaning |
|---|---|
$name | Button name and the field it reads (lower case); default Active. |
$link | Default url('/@object/active/%d'). |
short | A small icon button (html()->btn_active()). |
renderer | switch: a Bootstrap 5 form switch (Bootstrap 3 keeps the button). |
disabled | Shows the state without a link. |
no_ajax | No change_active class (the admin script toggles it in place). |
post | false: stays a plain link when the table POSTs its state-changing buttons. |
Example
Code
$rows = [
1 => ['id' => 1, 'name' => 'Spring sale', 'active' => 1],
2 => ['id' => 2, 'name' => 'Old banner', 'active' => 0],
];
return table($rows, ['no_pages' => 1])
->text('name')
->btn_active(['link' => '#toggle-%d', 'no_ajax' => 1])
->btn_active(['link' => '#toggle-%d', 'short' => 1])
->btn_active(['link' => '#toggle-%d', 'renderer' => 'switch']);Notes
- The labels come from the
pair_activedata handler. - Changing state is a write: in the admin with the CSRF guard on it POSTs with the token (
data-yf-post).
Bootstrap 3 and 5
renderer => switch is a form-check form-switch under Bootstrap 5 only.
See also: table/yes_no, form/active_box, html/btn_active