backend list item: how to get the item model id?

- 1 answer

Ad

please, how to get item's id in a partial used to display a action button in a back end list column ?

my partial is :

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="<?= Backend::url('author/plugin/nameofcontroller/create_from_course', 99999) ?>" class="btn btn-default btn-xs">new session</a>

where the 99999 need to be the dynamic value ( the id of the model of the list item)

if i put

<pre>
<?= //print_r($this->widget->list); ?>
</pre>

in the partial instead of the button code, i can see the needed id but it was in protected attribute so i can't accces it

seems so simple but .... spent already half day on it :-)

thanks for help

Ad

Answer

Ad

response with bonus here https://octobercms.com/forum/post/custom-button-with-model-id-for-backend-list-item

If you use the "partial" list-column type, then you have a few variables available to you inside that partial. Namely, $record, $value and $column. What you need is $record. So your partial would be:

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="<?= Backend::url('author/plugin/nameofcontroller/create_from_course', $record->id) ?>" class="btn btn-default btn-xs">new session</a>

Also, make sure you set clickable = false in your columns.yaml for this column.

Ad
source: stackoverflow.com
Ad