【问题标题】:Prestashop 1.7 renderform by admincontroller errorPrestashop 1.7 renderform 由 admincontroller 错误
【发布时间】:2018-11-06 10:17:06
【问题描述】:

对于我的模块,我需要使用助手生成一个表单。我在网上没有发现我的错误所以......我再次发布一些东西......

这里是我的 AdminYoutubeHomeController

<?php


class AdminYoutubeHomeController extends ModuleAdminController
{
    public function __construct()
    {
        $this->bootstrap = true;
        $this->display = 'view';
        parent::__construct();
        $this->meta_title = $this->l('Youtube');
        if (!$this->module->active) {
            Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
        }
    }

    public function renderView()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitYoutubeHomeModule')) == true) {
            $this->postProcess();
        }

        $this->context->smarty->assign([
            'youtube_dir', _PS_MODULE_DIR_.'youtubehome',
            'youtube_embeded' => "https://www.youtube.com/embed/",
            'youtubeLink' => Configuration::get('YOUTUBEHOME_LINK_VIDEO')

        ]);

        return $this->context->smarty->fetch(_PS_MODULE_DIR_.'youtubehome/views/templates/admin/youtubehome.tpl').$this->renderForm();
    }

    /**
     * Create the form that will be displayed in the configuration of your module.
     */
    public function renderForm()
    {
        $helper = new HelperForm();

        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $helper->module = $this;
        $helper->name_controller = $this->module->name;
        $helper->default_form_language = $this->context->language->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitYoutubeHomeModule';

        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
            .'&configure='.$this->module->name.'&tab_module='.$this->module->tab.'&module_name='.$this->module->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        );

        return $helper->generateForm(array($this->getConfigForm()));
    }

    /**
     * Create the structure of your form.
     */
    public function getConfigForm()
    {
        return array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Settings'),
                    'icon' => 'icon-cogs',
                ),
                'input' => array(
                    array(
                        'col' => 3,
                        'type' => 'text',
                        'prefix' => '<i class="icon icon-youtube-play"></i>',
                        'desc' => $this->l('Enter your youtube end link'),
                        'name' => 'YOUTUBEHOME_LINK_VIDEO',
                        'label' => $this->l('Link'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    public function getConfigFormValues()
    {
        return array(
            'YOUTUBEHOME_LINK_VIDEO' => Configuration::get('YOUTUBEHOME_LINK_VIDEO'),
        );
    }

    /**
     * Save form data.
     */
    public function postProcess()
    {
        $form_values = $this->getConfigFormValues();

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }

}

这里是错误

我的 tpl 文件位于 modules/youtubehome/views/templates/admin/youtubehome.tpl

我不想覆盖默认表单。你认为我做错了什么吗?

编辑帖子

这是 ps_version 的错误

【问题讨论】:

    标签: forms module controller prestashop helper


    【解决方案1】:

    尝试:

    $this->setTemplate('module:youtubehome/views/templates/admin/youtubehome.tpl');
    

    问候

    【讨论】:

    • 谢谢你的回答,我试试。我还有一个错误。控制器尝试在 theme/default/template/module:youtubehome/views/templates/admin/youtubehome.tpl' 中找到模板,但一无所获。很正常,我的模板在modules/youtubehome/views/templates/admin/youtubehome.tpl
    • 并尝试使用:$this->display(FILE, '/views/templates/admin/youtubehome.tpl');
    • 谢谢。我试过了,我有“警告:使用未定义的常量 FILE - 假定为 'FILE'(这将在 PHP 的未来版本中引发错误)”与 FILE 相同,我尝试使用 PS_MODULE_DIR 并且错误是“注意:未定义的索引:ps_version”
    • 试试:$this->display(dirname(FILE), '/views/templates/admin/youtubehome.tpl');
    • 谢谢,同样的错误:“警告:使用未定义的常量 FILE - 假定为 'FILE'(这将在 PHP 的未来版本中引发错误)”
    猜你喜欢
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 2022-10-21
    • 2017-11-10
    • 2021-06-14
    • 1970-01-01
    • 2018-06-01
    • 2018-05-15
    相关资源
    最近更新 更多