Put $listoption -> data > db in a html

Started by Jotade29, March 20, 2025, 06:28:17 PM

Previous topic - Next topic

Jotade29

V: 2.0.19

Hi, I want to insert the data I receive from the DB, from the $listOptions ... data => array ... db function, into an <a> to create a link. I'll leave a code snippet for better understanding. Let's suppose a user's data is loaded into the following listOptions.

$listOptions = array(
'id' => for example 1,
'title' => loremipsum,
'items_per_page' => 25,
'get_items' => array(
'function' => 'LoadMember (load data user)',
'params' => array(
$id,
),
),
'get_count' => array(
'function' => xxx,
'params' => array(
$id,
),
),
'columns' => array(
'username' => array(
'header' => array(
'value' => $txt['username'],
),
[b]'data' => array(
'db' => 'real_name',[/b]
),
...

In this example, in data db should see real_name, ejemplo: "Pablo", but I want to insert the value of data => db into an <a>. How can I add styling to the data? I'm not referring to styling the row; that's what the 'style' tag is for.

Thnx
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

All Colours Sam

You can use the "function" param for that:
heres a basic delete button I use

$anchor = '<a href="{href}" class="you_sure">{title}</a>';

'delete' => [
                    'header' => [
                        'value' => $this->utils->text('delete'),
                    ],
                    'data' => [
                        'function' => fn($rowData) => strtr($anchor, [
                            '{href}' => $scripturl . '?action=' . $action .';sa=delete;id=' . $rowData->getId(),
                            '{title}' => $this->utils->text('delete'),
                        ]),
                    ],
                ],

where rowData is an array with the data, you most likely will access it like this:  rowData['real_name']

This is for 2.1 but should work for 2.0 too, perhaps just replace the inline fn with a closure
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Advertisement: