link() table()
A column whose cells link somewhere, with the link and the value => text data as arguments.
table()->link($name, $link = '', $data = '', $extra = [])Options
| Option | Meaning |
|---|---|
$link | The URL; %d is the value of this column (or of link_field_name), %<field> any field of the row. |
$data | Value => text map shown instead of the value (a category id shows its name). |
(text options) | Every option of text(): link_field_name, rewrite, link_title, link_trim_width, class... |
Example
| Name | Category |
|---|---|
| Desk lamp | Lighting |
| Office chair | Chairs |
Code
$categories = [3 => 'Lighting', 5 => 'Chairs'];
$rows = [
1 => ['id' => 1, 'name' => 'Desk lamp', 'cat_id' => 3],
2 => ['id' => 2, 'name' => 'Office chair', 'cat_id' => 5],
];
return table($rows, ['no_pages' => 1])
->link('name', '#product-%d', '', ['link_field_name' => 'id'])
->link('cat_id', '#category-%d', $categories, ['desc' => 'Category']);Notes
- A link the admin may not open (
admin_methods, non-super-admin groups) is printed as plain text. - The link text is escaped; the URL goes into
hrefas given, so build it from site code.
Bootstrap 3 and 5
Links are mini buttons: btn btn-default btn-xs (Bootstrap 3), btn btn-outline-secondary btn-sm (5); set class for a plain link.
See also: table/text, table/btn, demo:table/filter