2015-09-24 55 views
0

我已經創建了一個自定義的模塊:添加自定義模塊選項卡在後端

模塊/ MyModule的/ mymodule.php

<?php 

if (!defined('_PS_VERSION_')) 
    exit; 

class mymodule extends Module 
{ 
    public function __construct() 
    { 
     $this->name = 'mymodule'; 
     $this->tab = 'quick_bulk_update'; 
     $this->version = '1.0.0'; 
     $this->author = 'MYMODULE'; 
     $this->need_instance = 0; 
     $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
     $this->bootstrap = true; 

     parent::__construct(); 

     $this->displayName = $this->l('MYMODULE'); 
     $this->description = $this->l('MYMODULE DESCRIPTION'); 

     $this->confirmUninstall = $this->l('¿Está seguro de desinstalar este módulo?'); 

     if (!Configuration::get('mymodule')) 
      $this->warning = $this->l('No se ha introducido ningún nombre'); 
    } 

    public function install() 
    { 
     if (Shop::isFeatureActive()) 
      Shop::setContext(Shop::CONTEXT_ALL); 

     if (!parent::install() || !Configuration::updateValue('mymodule', 'mymodule')) 
      return false; 
     return true; 
    } 

    public function uninstall() 
    { 
     if (!parent::uninstall() || 
      !Configuration::deleteByName('mymodule') 
     ) 
      return false; 

     return true; 
    } 

    public function getContent() 
    { 
     $output = null; 

     if (Tools::isSubmit('submit'.$this->name)) 
     { 
      $my_module_name = strval(Tools::getValue('mymodule')); 
      if (!$my_module_name 
       || empty($my_module_name) 
       || !Validate::isGenericName($my_module_name)) 
       $output .= $this->displayError($this->l('Valor de configuración incorrecto')); 
      else 
      { 
       Configuration::updateValue('mymodule', $my_module_name); 
       $output .= $this->displayConfirmation($this->l('Ajustes actualizados correctamente')); 
      } 
     } 
     return $output.$this->displayForm(); 
    } 

    public function displayForm() 
    { 
     // Get default language 
     $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); 

     // Init Fields form array 
     $fields_form[0]['form'] = array(
      'legend' => array(
       'title' => $this->l('Ajustes'), 
      ), 
      'input' => array(
       array(
        'type' => 'text', 
        'label' => $this->l('Valor de configuración'), 
        'name' => 'mymodule', 
        'size' => 20, 
        'required' => true 
       ) 
      ), 
      'submit' => array(
       'title' => $this->l('Guardar'), 
       'class' => 'button' 
      ) 
     ); 

     $helper = new HelperForm(); 

     // Module, token and currentIndex 
     $helper->module = $this; 
     $helper->name_controller = $this->name; 
     $helper->token = Tools::getAdminTokenLite('AdminModules'); 
     $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; 

     // Language 
     $helper->default_form_language = $default_lang; 
     $helper->allow_employee_form_lang = $default_lang; 

     // Title and toolbar 
     $helper->title = $this->displayName; 
     $helper->show_toolbar = true;  // false -> remove toolbar 
     $helper->toolbar_scroll = true;  // yes - > Toolbar is always visible on the top of the screen. 
     $helper->submit_action = 'submit'.$this->name; 
     $helper->toolbar_btn = array(
      'save' => 
       array(
        'desc' => $this->l('Guardar'), 
        'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. 
         '&token='.Tools::getAdminTokenLite('AdminModules'), 
       ), 
      'back' => array(
       'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 
       'desc' => $this->l('Back to list') 
      ) 
     ); 

     // Load current value 
     $helper->fields_value['mymodule'] = Configuration::get('mymodule'); 

     return $helper->generateForm($fields_form); 
    } 

} 

和我加入後端一個選項卡,也爲configurate值。我通過管理員>後端選項菜單。我以前創建的下一個文件:

模塊/ mymodule中/控制器/管理/ AdminMyModule.php

<?php 
class AdminMyModuleController extends ModuleAdminController { 

    public function __construct(){ 

    } 
} 

,並命名爲MyModule的正確顯示在後臺菜單中的選項卡,但是當我選擇它,加載的頁面不會顯示任何內容。 我需要顯示以上的displayForm函數的形式。當我進入modules> mymodule>配置時顯示此表單。此表格將值保存在ps_configuration表中。實際上,我只需要這個表單,就可以在配置表中保存一些值,甚至更多。

回答

0

最後我解決它以這樣的方式

class AdminMyModuleController extends ModuleAdminController { 

public function __construct() 
{ 
$this->bootstrap = true; 
$this->className = 'Configuration'; 
$this->table = 'configuration'; 

parent::__construct(); 

$this->fields_options = array(
'general' => array(
'title' => $this->l('Ajustes para configurar mi modulo'), 
'fields' => array(
'MYMODULE_IDCLIENTE' => array(
'title' => $this->l('Identificador de cliente'), 
'type' => 'text', 
'size' => 20, 
'required' => true 
), 
'MYMODULE_EXECUTION_INTERVAL_UNIT' => array(
'title' => $this->l('Intervalo de ejecución (unidad)'), 
'type' => 'select', 
'size' => 5, 
'required' => true, 
'identifier' => "execution_interval_unit", 
"desc" => "Indique si desea que la sincronización se realice cada x minutos, horas, días, semanas o meses.", 
'list' => array(
array("execution_interval_unit" => "1", "name" => 'Minutos'), 
array("execution_interval_unit" => "2", "name" => 'Horas'), 
array("execution_interval_unit" => "3", "name" => 'Días'), 
array("execution_interval_unit" => "4", "name" => 'Semanas'), 
array("execution_interval_unit" => "5", "name" => 'Meses') 
) 
), 
'MYMODULE_EXECUTION_INTERVAL_VALUE' => array(
'title' => $this->l('Intervalo de ejecución (valor)'), 
'type' => 'text', 
'size' => 20, 
'required' => true 
), 
), 
'submit' => array('title' => $this->l('Save')) 
), 
); 
} 
} 

希望這有助於其他。 Regards,

相關問題