We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Assets duplicating after forward

How i can prevent duplicating of assets after forwarding by dispatcher? For example:

In the BaseController was add a resources after that in some controller are forwarding to login page which are extending the BaseController. After that resources which adding in BaseController are duplicating.

PS: I'm sorry for my bad English.



2.5k

Could you include some source code from teh Basecontroller where you are including the asset and then the Login Controller you extend from Base Controller?

BaseController

public function initialize() {
        parent::initialize();
        $this->assets->collection('admin-main-js')
                ->addJs('assets/js/lib/jquery.js')
                ->addJs('assets/js/lib/angular.js')
                ->addJs('assets/js/admin/app.js');
        $this->addToTitle(_('...'));
}

SomeController extendet from Base

public function initialize() {        
        parent::initialize();
        $this->addToTitle(_('...'));
    }

public function indexAction() {
    $this->checkUserAccess(__METHOD__); // <- forwarding is inside
    ...
}


1.3k
edited Jun '16

Had the same issue. Try in BaseController

public function initialize()
{
        if ($this->dispatcher->wasForwarded()) return;
        ...