ZendFramework Headscript Helper - 使脚本独一无二
如何确保添加时 headScript 和 headStyle 帮助程序包含 css 文件仅一次?
我问的原因是我想在灯箱中显示一些内容以及所有 Flashmassages.Eg 通知(例如配置文件已成功编辑)。
要在灯箱中显示 flashmessages,我想检查布局脚本的顶部是否设置了它们,如果设置了,我想使用 headScript 帮助程序附加所需的 javascript 库。
问题是我此时无法控制已添加的脚本。也许在其他用例需要该库的页面上,它已经通过 addScript 添加了。
如何确保所有脚本只添加到我的助手中一次?
我已经检查过这些助手扩展了 Zend_View_Helper_Placeholder_Container_Standalone,它在内部使用 ArrayObject 来保存数据并提供 getter 和 getter。数组对象的设置器。
也许这里的解决方案是每次添加脚本文件时使用 ArrayObject?
How can I ensure that the headScript and headStyle helper include css files only once when added?
The reason I am asking is that I would like to display some contents in a lightbox and all Flashmassages.E.g. notifications like profile successfully edited.
To display flashmessages in the lightbox i would like to check at the top of my layout script if they are set, in case they are i would like to attach the required javascript library using the headScript helper.
The problem is that I have no control about the scripts which were already added at this point. Maybe at a page where the library is needed for an other use case, it has already been added with addScript.
How can I ensure all scripts are added only once to my helper?
I already checked that these helpers extend Zend_View_Helper_Placeholder_Container_Standalone which uses an ArrayObject internally to hold the data and provides getters & setter to the array object.
Maybe a solution here would be to check each time when adding a script file if it already exists using the ArrayObject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要路径和文件名相同,文件就只会添加一次。 Zend View Helpers 应该为您处理好这个问题。
As long as the paths and filenames are the same, the files will only be added once. The Zend View Helpers should take care of that for you.