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');



83.0k

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

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


24.0k

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') }}



83.0k

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 voltassetscollections.php <script src="/assets/js/jquery-1.10.1.min.js" type="text/javascript"></script>

we need to add this to docs



13.4k
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



29.6k

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') }}



13.4k

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') }}



29.6k
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')
            ;


13.4k

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 ...