Reputation: 10926
I want to add a new column to a Admin Controller, but I want this column to be a link to a specific Order instead of just the ID. So far, I have this:
<?php
class AdminDnDPaymentsController extends ModuleAdminController {
public function __construct() {
$this->table = 'dnd_payments';
$this->className = 'DnDPayment';
$this->fields_list = array(
'id_dnd_payments' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'id_order' => array('title' => $this->l('Order'), 'align' => 'center', 'width' => 80),
'bank' => array('title' => $this->l('Bank'), 'width' => 120),
'payer' => array('title' => $this->l('Payer name'), 'width' => 140),
'amount' => array('title' => $this->l('Amount'), 'width' => 80),
'reference' => array('title' => $this->l('Reference'), 'width' => 120),
'date_add' => array('title' => $this->l('Date add'), 'type' => 'date'),
);
$this->bootstrap = true;
parent::__construct();
//$this->addRowAction('view');
//$this->addRowAction('edit');
$this->addRowAction('delete');
}
}
Upvotes: 1
Views: 1178
Reputation: 4337
Use callbacks for columns when you wish to alter its appearance.
$this->fields_list = array(
'id_order' => array(
'title' => $this->l('Order'),
'align' => 'center',
'width' => 80,
'callback' => 'printOrderLink'
),
// rest of the fields
);
Now create a method which will handle the appearance...
public function printOrderLink($value, $row)
{
$link = $this->context->link->getAdminLink('AdminOrders').'&id_order='.(int)$value.'&vieworder';
return '<a href="'.$link.'">View order</a>';
}
So for every row on id_order
column, the printOrderLink
method will be called and a link to that order will be displayed instead of ID.
$value
will be the current row's order ID and $row
is an array which holds all column values for current row (useful if you need to modify column appearance based on another column value).
Upvotes: 1