Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Load CSS, JS files in modules directory

Hello friends,

I have 2 module directories



All assets files loaded and working with in /public/css/ directory, but I am need this: every module must be assets directory.



I am try for load any css or js files with volt. But I have get this error:

CssController handler class cannot be loaded

What is the best way for load assets files in module directories ? , Thanks.

You need to load those assets in controller in each module. Or register CssController before loading modules so it would be accessible in any controller.


Can you explain this with an example? I cant found any examples. thanks.

Where you have defined CssController and where you loading it ?


I am not defined any CssController, I am trying load css in module directory "/apps/backend/css/theme.css" with this



output on VOLT

{{ assets.outputCss() }}

getting this error

CssController handler class cannot be loaded

I said in previous post, I want load css, js etc.. on "\apps\backend\css\" directory.

per module must be have css and js directory and I need load assets in module directory etc: "\apps\backend\css\theme.css"



where you put this code ?

edited Dec '15

namespace KolayWeb\Backend\Controllers;

use Phalcon\DI;

use Phalcon\Mvc\Controller;

class ControllerBase extends Controller

public function onConstruct(){




``` ->addCss('css/theme.css') ``` where you put this code ?

edited Dec '15

And then where are you sing this ControllerBase ?


my structure




I am enter backend panel with this url



I think I can't explain my problem. I need to import “assets files” in “module directories”.

Each module must have “self assets directory” and CSS – JS files must import from module directory.

Hope I explained clearly.


edited Dec '15

Okay. First, when user request you page, whole application is loaded to index.php that means that you need to provide path to theme.css/theme.js from index.php directory. Put something like this in your BaseController:

class BaseController extends Controller
    public function initialize()
        $moduleName = $this->dispatcher->getModuleName();
        $this->assets->setTargetPath("js/combined-$moduleName.js") // its imporant, it will be created under /public/js
          ->setTargetUri("js/combined-$moduleName.js") // its imporant, its saying in view output there will be that link
          // ->addFilter(new Jsmin()) - on production you should add filter
          $this->assets->setTargetPath("css/combined-$moduleName.css") // its imporant, it will be created under /public/css
          ->setTargetUri("css/combined-$moduleName.css") // its imporant, its saying in view output there will be that link
          // ->addFilter(new Cssmin()) - on production you should add filter

Then your controllers should extend BaseController, and this class should be load before loading modules, or load this class in each module - your choice. Also consider changing class to asbtract class - cuz you not gonna ever use it as object/put actions in there.

If you want your files be automatically loaded without putting names there just get all file names in category using scandir and do addCss/addJs for each element.

edited Dec '15

Thanks for helping Jurigag.


Have little error, setTargetPath Method Not found in assets ? I am use phpstorm with phalcon latest version.

edited Dec '15

I am solved all problem with this code on BaseController onConstruct Method.


    ->addFilter(new \Phalcon\Assets\Filters\Cssmin());

Thanks again :)