如何在PrestaShop中创建助手列表管理模块?



我在模块的管理控制器中使用此代码,但它不起作用:

$this->fields_list = array(
'Num' => array(
'title' => $this->l('Numéro du ticket'),
'width' => 140,
'type' => 'text',
),
'client' => array(
'title' => $this->l('Client'),
'width' => 140,
'type' => 'text',
),
'email' => array(
'title' => $this->l('Email du client'),
'width' => 140,
'type' => 'text',
),  
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
$helper->actions = array('edit', 'delete', 'view');
$helper->identifier = 'Num';
$helper->show_toolbar = true;
$helper->title = 'HelperList';
$results = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'ticket INNER JOIN '._DB_PREFIX_.'customer where ps_customer.id_customer = ps_ticket.id_client');
$helper->generateList($results,$fields_list);

你必须定义表和类名:

$this->table = 'mytable';
$this->className = 'myClassCore';

下面是Prestashop 1.7模块开发中模块管理控制器中的帮助程序列表示例:

public function renderList()
{
$fields_list = array(
'id' => array(
'title' => $this->l('ID'),
'width' => 120,
'type' => 'text',
'search' => false,
'orderby' => false
),
'name' => array(
'title' => $this->l('Name'),
'width' => 120,
'type' => 'text',
'search' => false,
'orderby' => false
),
'id_group' => array(
'title' => $this->l('Group ID'),
'width' => 120,
'type' => 'text',
'search' => false,
'orderby' => false
),

'active' => array(
'title' => $this->l('Status'),
'width' => 140,
'active' => 'status',
'type' => 'bool',
'search' => false,
'orderby' => false
),
'date_add' => array(
'title' => $this->l('Date Added'),
'width' => 140,
'type' => 'datetime',
'search' => false,
'orderby' => false
),
'date_upd' => array(
'title' => $this->l('Date Updated'),
'width' => 140,
'type' => 'datetime',
'search' => false,
'orderby' => false
),
);
// multishop feature
if (Shop::isFeatureActive()) {
$this->fields_list['id_shop'] = array(
'title' => $this->l('ID Shop'),
'align' => 'center',
'width' => 25,
'type' => 'int'
);
}
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = false;
$helper->identifier = 'id';
$helper->actions = array('edit', 'delete');
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
$helper->listTotal = count(ModelClass::getlistdata());
$helper->show_toolbar = true;
$helper->toolbar_btn['new'] =  array(
'href' => (Context::getContext()->link->getAdminLink('AdminModules').'&addnew=true&configure='.$this->module->name),
'desc' => $this->l('Add new')
);
$helper->title = 'Title';
$helper->table = 'TableNameInDatabase';
$helper->currentIndex = AdminController::$currentIndex;
$helper->token = Tools::getAdminTokenLite('AdminModules');
return $helper->generateList(ModelClass::getlistdata(), $fields_list);
}

最新更新