PrestaShop$此->;上下文->;smarty是空的

PrestaShop$此->;上下文->;smarty是空的,prestashop,prestashop-1.6,Prestashop,Prestashop 1.6,我正在制作一个PrestaShop 1.6模块,奇怪的事情发生了。在本模块的配置页面中,我为用户提供了两个表单。一个用于配置自动电子邮件,另一个用于测试电子邮件。我的问题是,在提交第二个表单后,$this->context->smarty为空,因此出现以下错误: Fatal error: Call to a member function assign() on null in /Users/andre/Projects/Web/xxx/modules/closecustomerthreadem

我正在制作一个PrestaShop 1.6模块,奇怪的事情发生了。在本模块的配置页面中,我为用户提供了两个表单。一个用于配置自动电子邮件,另一个用于测试电子邮件。我的问题是,在提交第二个表单后,
$this->context->smarty
为空,因此出现以下错误:

Fatal error: Call to a member function assign() on null in /Users/andre/Projects/Web/xxx/modules/closecustomerthreademail/closecustomerthreademail.php on line 90
在第90行我有:
$this->context->smarty->assign('module\u dir',$this->\u path)位于此函数内部:

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

    $this->context->smarty->assign('module_dir', $this->_path);
    $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

    return $output.$this->renderForm();
}
public function sendEmail($to_email, $to_name = null){

    $id_lang = $this->context->language->id;
    $template_dir = _PS_MODULE_DIR_.$this->name.'/views/templates/email/';

    $vars = array(
        '{html}' => Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_HTML_BODY'),
        '{text}' => Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_TEXT_BODY')
    );

    require(_PS_CONFIG_DIR_.'config.inc.php');
    require_once(_PS_ROOT_DIR_.'/init.php');

    $send = Mail::Send(
        (int)$id_lang,
        'email',
        Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_SUBJECT'),
        $vars,
        $to_email,
        $to_name,
        null,
        null,
        null,
        null,
        $template_dir,
        false,
        (int)$this->context->shop->id,
        null
    );

    return $send;
}
这就是我如何在屏幕中添加两个表单(renderForm方法):
return$helper->generateForm(数组($This->getConfigForm(),$This->getTestForm())

后处理。很抱歉粘贴了这么多代码,我正在尝试提供我认为相关的所有详细信息

protected function postProcess()
{
    if(Tools::isSubmit('test_form')) {
        $this->sendTestEmailTo(Tools::getValue('CLOSECUSTOMERTHREADEMAIL_EMAIL_TO_TEST'));
    }
    elseif(Tools::isSubmit('config_form')) {

        $form_values = $this->getConfigFormValues('config_form');

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }
}
sendTestEmailTo
只有一个IF语句,然后调用此函数:

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

    $this->context->smarty->assign('module_dir', $this->_path);
    $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

    return $output.$this->renderForm();
}
public function sendEmail($to_email, $to_name = null){

    $id_lang = $this->context->language->id;
    $template_dir = _PS_MODULE_DIR_.$this->name.'/views/templates/email/';

    $vars = array(
        '{html}' => Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_HTML_BODY'),
        '{text}' => Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_TEXT_BODY')
    );

    require(_PS_CONFIG_DIR_.'config.inc.php');
    require_once(_PS_ROOT_DIR_.'/init.php');

    $send = Mail::Send(
        (int)$id_lang,
        'email',
        Configuration::get('CLOSECUSTOMERTHREADEMAIL_EMAIL_SUBJECT'),
        $vars,
        $to_email,
        $to_name,
        null,
        null,
        null,
        null,
        $template_dir,
        false,
        (int)$this->context->shop->id,
        null
    );

    return $send;
}
我看不出是什么原因导致
$this->context->smarty
null
。你有什么建议帮我调查一下吗

编辑

构造方法:

public function __construct()
{
    $this->name = 'closecustomerthreademail';
    $this->tab = 'others';
    $this->version = '1.0.0';
    $this->author = 'andre';
    $this->need_instance = 0;

    /**
     * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
     */
    $this->bootstrap = true;

    parent::__construct();

    $this->displayName = $this->l('Close Customer Thread e-mail');
    $this->description = $this->l('Sends an e-mail whenever you close a customer thread');

    $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');

    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}

在交付之前我无法确定,因此我必须这样做以解决重定向问题:

protected function postProcess()
{
    if(Tools::isSubmit('test_form')) {
        $this->sendTestEmailTo(Tools::getValue('CLOSECUSTOMERTHREADEMAIL_EMAIL_TO_TEST'));
    }
    elseif(Tools::isSubmit('config_form')) {

        $form_values = $this->getConfigFormValues('config_form');

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

    $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    Tools::redirectAdmin($actual_link);
}

我很高兴你解决了这个问题。但我想问题在于:

require(_PS_CONFIG_DIR_.'config.inc.php');
require_once(_PS_ROOT_DIR_.'/init.php');

删除这些行:),你不应该在类方法中包含这些文件。

你能发布你的构造方法吗?谢谢:)@sarcom刚刚做了,谢谢你说得对,我不需要插入它。我这么做是因为我在PrestaShop论坛上看到了另一个帖子。