ZendFramework Headscript Helper - 使脚本独一无二

发布于 2024-12-16 17:55:15 字数 680 浏览 1 评论 0原文

如何确保添加时 headScriptheadStyle 帮助程序包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日浅笑〃 2024-12-23 17:55:15

只要路径和文件名相同,文件就只会添加一次。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文