Объект Prestashop Smarty отсутствует в модуле контроллера - PullRequest
0 голосов
/ 22 июня 2019

Prestashop версия 1.7.5.2

В контроллере моего модуля я пытаюсь присвоить значение smarty, чтобы оно было в шаблоне.

Проблема в том, что отсутствует экземпляр smarty (ноль) , поэтому невозможно вызвать метод assign():

Вызов функции-члена assign () со значением NULL

// Location: /modules/mymodule/mymodule.php

class MyModule extends Module {

     /**
     * MyModule constructor.
     * @param null         $name
     * @param Context|null $context
     */
    public function __construct($name = null, Context $context = null)
    {
        $this->name = 'mymodule';
        $this->tab = 'front_office_features';
        $this->version = '0.9.0';
        $this->author = 'toesslab';
        $this->ps_versions_compliancy = [
            'min' => '1.7',
            'max' => '1.7'];
        $this->bootstrap = true;
        parent::__construct($name, $context);
        $this->displayName = $this->trans('My Module');
        $this->description = $this->trans('');
        $this->confirmUninstall = $this->trans('Are you sure you want to uninstall?');
        if (!Configuration::get('MYMODULE_NAME')) {
            $this->warning = $this->trans('No name provided.');
        }
    }


    /**
     * @param $params
     * @return string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookDisplayAdminProductsExtra()
    {
        $viewData = [
            'foo' => $bar,
            'bar' => $foo,
        ];
        // context is present but not smarty
        $this->context->smarty->assign($viewData);

        return $this->display(__File__, 'tabadminproduct.tpl');
    }
}

Также я попытался сначала получить экземпляр context:

$context = Context::getContext();

и я попробовал

$this->smarty->assign($viewData);

При отладке smarty отсутствует в контексте:

enter image description here

1 Ответ

0 голосов
/ 23 июня 2019

обидное:

В родительском конструкторе я снова передал $name и $context в качестве параметра, который затем будет null наверняка однажды возвращен дочернему элементу.

parent::__construct($name, $context);

Вместо

parent::__construct();
...