如何将自定义ID添加到表单字段prestaShop表单帮助器

时间:2019-04-11 10:31:30

标签: prestashop-1.6

伙计们,我是新手prestashop,我正在开发一个模块,在后台我使用助手表格,如何在模块配置页面的表单字段中添加ID,目前我需要在类别中添加类或ID树形帮手? 我尝试跟随,但不起作用?

array(
                    'type' => 'categories',
                    'label' => 'tree categories',
                    'name' => 'type_categories',
                    'class'=>'cat-test',
                    'tree' => array(
                        'root_category' => 2,
                        'id' => 'id_category',
                        'name' => 'name_category',
                        'selected_categories' => array(),
                    )
                ),

1 个答案:

答案 0 :(得分:0)

您无法使用帮助程序表单在树上管理ID /类。

因此,您可以在模板上进行操作:

PHP:

public function getContent(){ return $this->renderCategories(); }

protected function renderCategories() {
   $root = Category::getRootCategory();
    $selected_cat = array();
    $tree = new HelperTreeCategories('categories-treeview');
    $tree->setUseCheckBox(true)
            ->setAttribute('is_category_filter', $root->id)
            ->setRootCategory($root->id)
            ->setSelectedCategories($selected_cat)
            ->setUseSearch(true);
    $this->smarty->assign(array(
        'tree' => $tree->render(),
        'formlink' => $this->context->link->getAdminLink('AdminModules', false)
        . '&configure=' . $this->name
        . '&tab_module=' . $this->tab
        . '&module_name=' . $this->name
        . '&token=' . Tools::getAdminTokenLite('AdminModules')
    ));
    return $this->display(__FILE__, '/views/templates/admin/configure.tpl');
}

TPL:

<div class="panel col-lg-12" >
<form id="module_form" class="defaultForm form-horizontal" action="{$formlink}" method="post" novalidate="">
    <h3><i class="icon icon-cogs"></i>Category</h3><br/>

                            <!--TREE-->
    <div class="form-group">
        <div class="col-lg-2">
            <span class="pull-left">
                <label class="control-label" for="category_block" id="Category"> 
                    Categories : 
                </label>
            </span>
        </div>
        <div class="col-lg-9">
            <div id="YOUR ID" class="YOUR CLASS">
                {$tree}                  
            </div>
        </div>
    </div>

    <div class="panel-footer col-lg-12" id="footer-submit"  >
         <!--SUBMIT submitAddRule-->
        <button type="submit" value="1" id="submitCatThe" name="submitCatThe" class="btn btn-default pull-right"/>
        <i class="process-icon-save">
        </i>
        Save

    </div>
</form>
</div>