Prestashop 1.7.5.2版
在模块控制器中,我尝试为smarty
分配一个值,以便将其包含在模板中。
问题是似乎没有灵巧的实例存在(空),因此无法调用assign()
方法:
在null上调用成员函数Assign()
// 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
时:
答案 0 :(得分:0)
令人尴尬:
在父母构造函数中,我再次传递了$name
和$context
作为参数,一旦返回给孩子,就可以确定为null
。
parent::__construct($name, $context);
代替
parent::__construct();