Автор Тема: Редактирование текста модуля из админки  (Прочитано 1621 раз)

08 Апрель 2014, 02:53:40
  • Новичок
  • *
  • Сообщений: 3
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Помогите разобраться. Поставил модуль болванку, выводящую несколько div-блоков, в этих блоках должен располагаться текст. Как сделать так чтобы этот текст можно было редактировать из бэк офиса? :o
08 Апрель 2014, 10:29:50
Ответ #1
  • Ветеран
  • *****
  • Сообщений: 105673
  • Репутация: +39553/-0
    • Просмотр профиля
    • Webstudio UwK
Creating a PrestaShop module
Работа с контентом в админке
public function getContent()
{
    $output = null;
    if (Tools::isSubmit('submit'.$this->name))
    {
        $my_module_name = strval(Tools::getValue('MYMODULE_NAME'));
        if (!$my_module_name  || empty($my_module_name) || !Validate::isGenericName($my_module_name))
            $output .= $this->displayError( $this->l('Invalid Configuration value') );
        else
        {
            Configuration::updateValue('MYMODULE_NAME', $my_module_name);
            $output .= $this->displayConfirmation($this->l('Settings updated'));
        }
    }
    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('Settings'),
        ),
        'input' => array(
            array(
                'type' => 'text',
                'label' => $this->l('Configuration value'),
                'name' => 'MYMODULE_NAME',
                'size' => 20,
                'required' => true
            )
        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'button'
        )
    );
     
    $helper = new HelperForm();
     
    // Module, t    oken 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('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')
        )
    );
     
    // Load current value
    $helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');
     
    return $helper->generateForm($fields_form);
}
Cоздание интернет сайтов Webstudio UwK
08 Апрель 2014, 21:10:00
Ответ #2
  • Новичок
  • *
  • Сообщений: 3
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Виталий, спасибо что откликнулись на мою проблему. Но скажите пожалуйста, что с этим кодом делать, а то я нубоват в престе ::)
09 Апрель 2014, 14:09:27
Ответ #3
  • Ветеран
  • *****
  • Сообщений: 105673
  • Репутация: +39553/-0
    • Просмотр профиля
    • Webstudio UwK
Функции getContent(), displayForm() позволяют добавить возможность редактировать модуль в админке.
getContent() - указвает, что модуль имеет изменяемые параметры, выводит информацию в модуле при нажатии Настроить.
displayForm() - показывает поля, содержимое которых можно менять.
Cоздание интернет сайтов Webstudio UwK
09 Апрель 2014, 23:43:39
Ответ #4
  • Новичок
  • *
  • Сообщений: 3
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля
Функции getContent(), displayForm() позволяют добавить возможность редактировать модуль в админке.
getContent() - указвает, что модуль имеет изменяемые параметры, выводит информацию в модуле при нажатии Настроить.
displayForm() - показывает поля, содержимое которых можно менять.

То есть displayForm вставляется внутрь div-а в котором редактируемое содержимое? А куда getContent()?
(извеняюсь за тугость ;D)
10 Апрель 2014, 11:19:45
Ответ #5
  • Ветеран
  • *****
  • Сообщений: 33325
  • Репутация: +26771/-0
    • Просмотр профиля
Creating a PrestaShop module
Там все расписано - Diving in displayForm()....
Как сделать форму для редактируемыз полей в модуле, как менять поля,
    $helper->module: requires the instance of the module that will use the form.
    $helper->name_controller: requires the name of the module.
    $helper->token: requires a unique token for the module. getAdminTokenLite() helps us generate one.
    $helper->currentIndex:
    $helper->default_form_language: requires the default language for the shop.
    $helper->allow_employee_form_lang: requires the default language for the shop.
    $helper->title: requires the title for the form.
    $helper->show_toolbar: requires a boolean value – whether the toolbar is displayed or not.
    $helper->toolbar_scroll: requires a boolean value – whether the toolbar is always visible when scrolling or not.
    $helper->submit_action: requires the action attribute for the form's <submit> tag.
    $helper->toolbar_btn: requires the buttons that are displayed in the toolbar. In our example, the "Save" button and the "Back" button.
    $helper->fields_value[]: this is where we can define the value of the named tag.
25 Февраль 2016, 15:49:27
Ответ #6
  • Пользователь
  • **
  • Сообщений: 60
  • Репутация: +0/-0
  • Сообщество PrestaShop
    • Просмотр профиля