ufk*_*ufk 2 php prestashop prestashop-1.7
我正在学习将模块写入 prestashop 1.7,目前我正在尝试加载用户尝试配置模块时将使用的 css 和 js 文件。
这是我的模块的代码:
class TuxInModComments extends Module
{
function __construct()
{
$this->name = 'tuxinmodcomments';
$this->tab = 'quick_bulk_update';
$this->version = '0.1';
$this->author = 'Kfir Ozer';
$this->displayName = 'Tux-In Comments and Ranks';
$this->description = 'With this module, your costumers will be able to grade and comment your products';
$this->bootstrap = true;
parent::__construct();
}
public function install() {
parent::install();
$this->registerHook('actionAdminControllerSetMedia');
return true;
}
public function processConfiguration()
{
if (Tools::isSubmit('mymod_pc_form')) {
$enable_grades = Tools::getValue('enable_grades');
$enable_comements = Tools::getValue('enable_comments');
$csvFile = Tools::getValue('csv_file');
die(var_export($csvFile));
Configuration::updateValue('MYMOD_GRADES', $enable_grades);
Configuration::updateValue('MYMOD_COMMENTS', $enable_comements);
$this->context->smarty->assign('confirmation', 'ok');
}
}
public function assignConfiguration()
{
$enable_grades = Configuration::get('MYMOD_GRADES');
$enable_comments = Configuration::get('MYMOD_COMMENTS');
$this->context->smarty->assign('enable_grades', $enable_grades);
$this->context->smarty->assign('enable_comments', $enable_comments);
}
public function hookActionAdminControllerSetMedia($params){
$this->registerStylesheet('module-tuxinmodcomments-css','modules/tuxinmodcomments/js/getcontent.css');
$this->registerJavascript('module-tuxinmodcomments-js','modules/tuxinmodcomments/js/getcontent.js');
}
public function getContent() {
$this->processConfiguration();
$this->assignConfiguration();
return $this->display(__FILE__,'getContent.tpl');
}
}
Run Code Online (Sandbox Code Playgroud)
所以我用名称注册了 admin set Media 挂钩,actionAdminControllerSetMedia但它似乎没有设置样式表和 javascript 的功能,因为我得到了相同的错误:Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "registerStylesheet" OR "registerJavascript" of class "AdminModulesController"。
我对此真的很陌生..我读到我需要在前端控制器中设置它..但这是否意味着它将出现在常规页面而不是配置页面中?
不知道如何解决这个问题并且有点困惑,所以任何有关该问题的信息将不胜感激。
要加载 CSS 或 JS,您必须使用此钩子和以下代码片段:
public function hookDisplayBackOfficeHeader()
{
$this->context->controller->addCSS($this->_path.'pathtocss/module.css', 'all');
$this->context->controller->addJS($this->_path.'pathtojs/module.js', 'all');
}
Run Code Online (Sandbox Code Playgroud)
享受 :)
PS:您必须先注册显示后台标题挂钩
| 归档时间: |
|
| 查看次数: |
6863 次 |
| 最近记录: |