So, I have a bunch of controllers and views in a project. And I want to set my assets (CSS and JavaScript) just once instead of replicate it to every controller that have views. How can I do that?
For each new controller that I have I need to put this code to get the assets loaded:
private function loadAssets($isProduction)
{
define("csspath","application/public/css/");
define("jspath","application/public/js/");
if($isProduction){
$this->assets
->addCss(csspath.'compiled-output.css');
$this->assets
->addJs(jspath.'compiled-output.js');
}else{
$this->assets
->addCss(csspath.'bootstrap.min.css', true)
->addCss(csspath.'master/styles.dashboard.css', true);
$this->assets
->addJs(jspath.'jquery.min.js', true)
->addJs(jspath.'master/module.animations.js', true)
->addJs(jspath.'master/module.actions.js', true);
}
}
Where can I set this function to load automatically into all my other controllers/views? I've tried IndexController
and ControllerBase
, but they didn't worked.