2017-02-23 56 views
3
  1. 从数据库中检索该复选框是这么长时间,它会向下,有没有什么办法让它为四层
  2. 的“所有域”复选框,所有复选框必须点击时检查。

这是怎么做的?
我的代码: -复选框造型,使之检查

protected function getConfigForm() 
    {   
     $sql = 'SELECT id_order_state,name FROM '._DB_PREFIX_.'order_state_lang'; 
     $results = Db::getInstance()->ExecuteS($sql); 

     $values_query = array(array(
      'id' => 'AllFields', 
      'name' => $this->l('All Fields'), 
      'val' => 'All', 
     )); 
     foreach ($results as $row) { 
      $values_query[] = array(
       'id' => 'OrderID', 
       'name' => $this->l($row['name']), 
       'val' => $row['id_order_state'], 
       'required' => true, 
      ); 
     } 

     return array(
      'form' => array(
       'legend' => array(
        'title' => $this->l('Settings'), 
        'icon' => 'icon-cogs', 
       ), 
       'input' => array(     
        array(
         'type' => 'checkbox', 
         'label' => $this->l('Select Required Status'), 
         'required' => true, 
         'values' => array(
          'query' => $values_query, 
          'id' => 'id', 
          'name' => 'name' 
         ), 
        ), 
       ), 
       'submit' => array(
        'title' => $this->l('Save'), 
       ), 
      ), 
     ); 
    } 

回答

0

联系方式使用/adminXXX/themes/default/template/helpers/form/form.tpl模板文件中呈现。

在班/classes/helper/Helper.php有一个方法createTemplate()

public function createTemplate($tpl_name) 
{ 
    if ($this->override_folder) { 
     if ($this->context->controller instanceof ModuleAdminController) { 
      $override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name; 
     } elseif ($this->module) { 
      $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; 
     } else { 
      if (file_exists($this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name)) { 
       $override_tpl_path = $this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name; 
      } elseif (file_exists($this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name)) { 
       $override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name; 
      } 
     } 
    } elseif ($this->module) { 
     $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name; 
    } 

    if (isset($override_tpl_path) && file_exists($override_tpl_path)) { 
     return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty); 
    } else { 
     return $this->context->smarty->createTemplate($this->base_folder.$tpl_name, $this->context->smarty); 
    } 
} 

正如你可以在这个方法中看到的,你必须通过创建这个文件/modules/my_module/views/templates/admin/_configure/helpers/form/form.tpl来覆盖你的模块里面默认的管理模板的可能性:

{extends file="helpers/form/form.tpl"} 
{block name="input"} 
    {if $input.type == 'checkbox'} 
     {if isset($input.expand)} 
      <a class="btn btn-default show_checkbox{if strtolower($input.expand.default) == 'hide'} hidden{/if}" href="#"> 
       <i class="icon-{$input.expand.show.icon}"></i> 
       {$input.expand.show.text} 
       {if isset($input.expand.print_total) && $input.expand.print_total > 0} 
        <span class="badge">{$input.expand.print_total}</span> 
       {/if} 
      </a> 
      <a class="btn btn-default hide_checkbox{if strtolower($input.expand.default) == 'show'} hidden{/if}" href="#"> 
       <i class="icon-{$input.expand.hide.icon}"></i> 
       {$input.expand.hide.text} 
       {if isset($input.expand.print_total) && $input.expand.print_total > 0} 
        <span class="badge">{$input.expand.print_total}</span> 
       {/if} 
      </a> 
     {/if} 

     {* HERE WE DEFINE A CHECKBOX CHECK_ALL *} 
     <input type="checkbox" id="check_all" name="check_all" data-name="{$input.name}" value="1" /> 

     {foreach $input.values.query as $value} 
      {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]} 

      {* HERE YOU CAN REARRANGE THE CHECKBOXES AS YOU WANT *} 
      <div class="checkbox{if isset($input.expand) && strtolower($input.expand.default) == 'show'} hidden{/if}"> 
       {strip} 
        <label for="{$id_checkbox}"> 
         <input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" class="{if isset($input.class)}{$input.class}{/if}"{if isset($value.val)} value="{$value.val|escape:'html':'UTF-8'}"{/if}{if isset($fields_value[$id_checkbox]) && $fields_value[$id_checkbox]} checked="checked"{/if} /> 
         {$value[$input.values.name]} 
        </label> 
       {/strip} 
      </div> 
     {/foreach} 
    {else} 
     {$smarty.block.parent} 
    {/if} 
{/block} 

{* HERE WE DEFINE THE JAVASCRIPT THAT WILL ANIMATE THE CHECK ALL CHECKBOX *} 
<script type="text/javascript"> 
    $("#check_all").on('change', function() { 
     $("input[name=" + $(this).data('name') + "]").prop('checked', true); 
     $(this).prop('checked', false); 
    }); 
</script> 

该模板将用于模块中定义的每个管理控制器。

我没有测试这个代码,你将不得不根据你的需要来调整它,但总体概念在这里。

+0

我想在配置页面不在管理控制器页面。那可以在那里应用吗? –

+0

模块配置页面是一个管理控制器,所以它应该工作。 –