2017-03-07 9 views
0

私はPrestashop 1.7を使用しており、学習目的でEAN13ジェネレータモジュールを開発中です。 データベースを更新する際に、構成関数を使用して値を更新しようとしましたが、ページを再読み込みしても何も更新しないためです。Prestashop - 設定ページでDB値が更新されない

製品のEAN13を生成するために、フォームに「C_CODE」と「B_CODE」の値を設定します。ここ は、関数を呼び出すコードです:

public function getContent() { 
    return $this->renderForm().$this->postForm(); 
} 

public function postForm() { 

    if (Tools::isSubmit('submitConf')) { //Cambiamos valores 

     Configuration::updateValue('C_CODE', Tools::getValue('C_CODE_')); 
     Configuration::updateValue('B_CODE', Tools::getValue('B_CODE_')); 

     return $this->displayConfirmation($this->l('Settings changed')); 
    } 

    return ''; 

} 

そして、これらは私の「renderForm」です。私は 'currentIndex'についての問題だと思いますが、解決できません。

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

    // Init fields from an array 
    $fields_form[0]['form'] = array(
     'legend' => array(
     'title' => $this->l('Configuración del EAN'), 
      ), 
     'input' => array(
      array(
       'type' => 'text', 
       'label' => $this->l('Código del país'), 
       'name' => 'C_CODE', 
       'size' => 10, 
       'required' => true 
       ), 
      array(
       'type' => 'text', 
       'label' => $this->l('Código de la empresa'), 
       'name' => 'B_CODE', 
       'size' => 20, 
       'required' => true 
       ) 
      ), 
     'submit' => array(
      'title' => $this->l('Generar EAN13'), 
      'class' => 'btn btn-default pull-center' 
      ) 
     ); 

    $helper = new HelperForm(); 

    $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 = 'submitConf'; 
    $helper->toolbar_btn = array(
     'save' => 
     array(
      'desc' => $this->l('Save'), 
      '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') 
     ) 
    ); 


    $helper->fields_value['C_CODE'] = Configuration::get('C_CODE'); 
    $helper->fields_value['B_CODE'] = Configuration::get('B_CODE'); 

    //TODO: Fill with toolbars and more options 

    return $helper->generateForm($fields_form); 

} 

ご協力いただきありがとうございます。

答えて

0

getContent()メソッドでは、逆の順序でフォームメソッドを呼び出す必要があります。

最初に設定値を保存してからフォームを表示する必要があります。

public function getContent() { 
    return $this->postForm().$this->renderForm(); 
} 
+0

私はrenderForm()の前にpostForm()をcoppiedしています。私は機能の内容を凝縮したことを意味します。つまり、prestashopの多くのモジュールがpostForm()の前にrenderForm()を呼び出しているので、私はそのメソッドを見ていました。答えてくれてありがとう、非常にうまくいく! –

関連する問題