CodeIgniter - 容器视图,用于从这些子视图中获取子视图所需的脚本(js)列表
我有一个打开容器视图的控制器。然后,容器将页面的构建交给几个视图,包括“html_meta”视图和“top_bar”、“side_bar”、“content”视图。然而,内容包含几个不同的视图,其中太多可以被视为小工具,或包含不同数据、脚本操作的小型 HTML div。
问题: 如果我希望 HTML 标头/元仅包含特定小工具视图所需的脚本,那么小工具视图是否可以将必要的脚本组件发送回容器视图,以便容器视图可以处理它们并将脚本添加到 html 头部?
- 如果有帮助,我可以包含代码,但现在,我认为这里会变得混乱。但是,如果您需要代码来可视化它,没问题。谢谢!
I have a controller that opens a container view. The container then hands the building of the page to several views including the "html_meta" view and the "top_bar", "side_bar", "content" views. However, the content contains several different views too many of which can be considered gadgets, or small contained html divs with different data, script actions.
Question:
If I want the HTML header/meta to include only the scripts that that the specific gadget views need, is there a way for the gadget views to send the necessary script components back up the line to the container view so that it can process them and add the scripts to the html head?
- If it helps I can include the code, but for now, I think it gets messy here. However, if you need code to visualize it, no problem. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
举个例子,我的控制器调用主
container
但我必须将来自另一个视图的内容传递给它然后
layout/container.php
包含几个这是可能的,但它是不是子视图“通知”“html_meta”包含它需要的 JavaScript,因为您的视图是从主容器渲染到子视图的。
您可以做的是为外部 java 创建一个帮助器脚本。我正在考虑为每个小部件创建一个 javascript 组,例如
然后在控制器函数中您还传递这些脚本,或者可能传递您的构造函数。
现在,您可以在
layout/container.php
中访问$custom_js
。但它还没有出现在layout/html_meta
中。因此,我将其分配给一个数组,然后再次将其传递给layout/html_meta
。然后,在您的
layout/html_meta
中,您现在可以使用$custom_js
插入除常用脚本之外的其他 JavaScript。As an example my controller calls the main
container
but I have to pass it my content which is from another view as suchThen
layout/container.php
contains severalIt's possible but it's not the subviews "informing" the "html_meta" to include the javascripts that it needs because your views are rendered from the main container down to the sub views.
What you can do is create a helper for your external java scripts. I'm thinking of having a javascript group for each of your widgets such as
Then in your controller function you also pass those scripts, or possible your constructor.
So now,
$custom_js
is accessible in yourlayout/container.php
. But it's not yet inlayout/html_meta
. So I'll assign this to an array, and pass it again tolayout/html_meta
.Then in your
layout/html_meta
, you can now use$custom_js
to insert additional javascripts aside from your common scripts.