[英]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. 在我的网站上,我有一些带有jquery灯箱的页面和一些没有灯箱的页面,用于加载我在控制器函数中使用的以下软件包,该函数加载该软件包并将其分配给占位符。
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, 但是在我的volt主模板(主模板)中,我定义了如下的占位符,
{{ assets.outputJs('lightboxJs') }}
{{ assets.outputCss('lightboxCss') }}
this works fine as long we this loadJSlightbox2 functions is called when loading the page. 只要在加载页面时调用此loadJSlightbox2函数,此方法就可以正常工作。 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 Phalcon \\ Assets \\ Exception:该集合在管理器中不存在
How do i archive this optional plugin behavior in with phalcon asset management tools in my web application ? 如何在我的Web应用程序中使用Phalcon资产管理工具来归档此可选插件的行为?
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 %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.