如何在PrestaShop中创建一个helperlist管理模块?

时间:2018-09-12 16:06:41

标签: prestashop-1.6

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

    $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);

2 个答案:

答案 0 :(得分:0)

您必须定义表和类名:

<div class="row">
    <div class="input-field col s8 offset-s2">
        <select asp-for="Type" class="validate" asp-items="Html.GetEnumSelectList<FieldType>()" required>
            <option disabled selected>Choose your option</option>
        </select>
        <label for="Type">Type<span style="color:red">*</span></label>
    </div>
</div>

答案 1 :(得分:0)

这是 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);
}