简体   繁体   中英

Phalcon - Asset Management - The collection does not exist in the manager

In my website i have some pages with jquery lightbox and some pages without lightbox, to load the packages i use following in my controller function which loads the package and assign that to the placeholder.

public function loadJSLightbox2()
{
    $this->assets
        ->collection('lightboxJs')
        //->setPrefix($this->config->site->cloud_url)
        ->addJs('web/dist/lightbox2/dist/js/lightbox.min.js');
    $this->assets
        ->collection('lightboxCss')
        //->setPrefix($this->config->site->cloud_url)
        ->addCss('web/dist/lightbox2/dist/lightbox.min.css');
}

However in my volt main template (master template) i have define the place holders like below,

 {{ assets.outputJs('lightboxJs') }}
 {{ assets.outputCss('lightboxCss') }}

this works fine as long we this loadJSlightbox2 functions is called when loading the page. In pages where i dont need to load the plugin (where these two asset are empty) i get error called as below.

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

How do i archive this optional plugin behavior in with phalcon asset management tools in my web application ?

I fixed the issue using following code,

{% for key, collection in assets.getCollections() %}
    {% if key == 'origin' %}
        {{ assets.outputJs('origin') }}
    {% endif %}
    {% if key == 'lightboxJs' %}
        {{ assets.outputJs('lightboxJs') }}
    {% endif %}
    {% if key =='colorboxJs' %}
        {{ assets.outputJs('colorboxJs') }}
    {% endif %}
{% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM