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 Management

Hello all!!! How to use a Assets Management in volt?

Phalcon\Assets\Exception: The collection does not exist in the manager

in volt {{ assets.outputJs('footer') }}

in controller: $this->assets->collection('footer') ->addJs('assets/js/jquery-1.10.1.min.js') ->addJs('assets/js/jquery.jqtransform.js');



98.9k

It seems the 'assets' service is registered as open instead of shared in the DI, it must be:

$di->setShared('assets', 'Phalcon\Assets\Manager');


42.1k

Phalcon\Assets\Exception: The collection does not exist in the manager

in services: $di->set('assets', function () { return new Phalcon\Assets\Manager(); }, true);

in ControllerBase: public function initialize() { $this->assets->collection('footer')->addJs('assets/js/jquery-1.10.1.min.js'); }

in app/views/index.volt: {{ assets.outputJs('footer') }}



98.9k

Can you run this in a plain php file?

<?php

$di = new Phalcon\DI();

$di->set('assets', function () {
    return new Phalcon\Assets\Manager();
}, true);

$di->set('url', function () {
    return new Phalcon\Mvc\Url();
}, true);

$di['assets']->collection('footer')->addJs('assets/js/jquery-1.10.1.min.js');

$di['assets']->outputJs('footer');

it works $ php volt_assets_collections.php <script src="/assets/js/jquery-1.10.1.min.js" type="text/javascript"></script>

we need to add this to docs



21.1k
edited Oct '14

i still get.

Phalcon\Assets\Exception: The collection does not exist in the manager

When i try

$this->assets
->collection('header')
->addJs('//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js', false)
->addJs('//oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js', false);

I am extending Vokuro app.

I have tried

$di->set('assets', function () {
    return new Phalcon\Assets\Manager();
}, true);

And

$di->setShared('assets', 'Phalcon\Assets\Manager');

I am using 1.3.3



43.9k

Hi,

I think that "assets" service is registred by default in a phalcon's mvc full stack app. I never use assets registration in the di. And in main view file, I use:

{{ assets.outputJs('header') }}



21.1k

Hi, I have that too but when i use ->collection('header')->addJs('hgh',true); do i get that error.

Hi,

I think that "assets" service is registred by default in a phalcon's mvc full stack app. I never use assets registration in the di. And in main view file, I use:

{{ assets.outputJs('header') }}



43.9k
edited Oct '14

when using local ressources, I do not use the "true" argument and it works OK ...


        $this->assets
            ->collection('header')
            ->addJs('js/vendor/modernizr.js')
            ->addJs('js/vendor/jquery.js')
            ;


21.1k

Great, thanks that did it! i wish i could give you the right answer for that one :)

when using local ressources, I do not use the "true" argument and it works OK ...