我想向管理员控制器添加一个新列,但我希望此列是指向特定订单的链接,而不仅仅是ID。到目前为止,我有这个:
<?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');
}
}
答案 0 :(得分:1)
当您希望更改其外观时,请对列使用回调。
$this->fields_list = array(
'id_order' => array(
'title' => $this->l('Order'),
'align' => 'center',
'width' => 80,
'callback' => 'printOrderLink'
),
// rest of the fields
);
现在创建一个处理外观的方法......
public function printOrderLink($value, $row)
{
$link = $this->context->link->getAdminLink('AdminOrders').'&id_order='.(int)$value.'&vieworder';
return '<a href="'.$link.'">View order</a>';
}
因此,对于id_order
列上的每一行,都会调用printOrderLink
方法,并显示指向该订单的链接。
$value
将是当前行的订单ID,而$row
是一个包含当前行的所有列值的数组(如果您需要根据其他列值修改列外观,则非常有用) )。