I want to add JS and CSS files to back office in my module. But I get error: Attempted to call an undefined method named \"registerStylesheet\" of class \"AdminModulesController
Try with :
$this->addJs(
_PS_MODULE_DIR_ .'objet/views/js/feature.js',
'all'
);
$this->addCss(
_PS_MODULE_DIR_ .'objet/views/css/feature.css',
'all'
);
Regards
The explanation of which methods to use:
These are FrontController
methods in PrestaShop 1.7: registerJavascript
and registerStylesheet
.
These are legacy (deprecated) FrontController
methods in PrestaShop 1.7: addJS
and addCSS
.
These are AdminController
methods in PrestaShop 1.7, 1.6, 1.5: addJS
and addCSS
.
So, the correct example to add a JS and a CSS files for a back-office (i.e. for AdminController) via a module class is:
public function hookActionAdminControllerSetMedia($params)
{
// Adds your's CSS file from a module's directory
$this->context->controller->addCSS($this->_path . 'views/css/example.css');
// Adds your's JavaScript file from a module's directory
$this->context->controller->addJS($this->_path . 'views/js/example.js');
}
For an additional information see my yet another answer how to register JavaScript in a back-office (in admin pages). I have updated it after this question.