代码点火器侧边栏
我有一个小问题,我不知道该怎么办。
我的所有页面上都有一个带有
- 标题
- 内容
- 侧边栏
- 页脚
的模板,唯一需要更改的是内容,那么我如何将数据传递到我的侧边栏/页脚,
我需要制作一个控制器吗?或者我是否需要创建一个库并将其加载到我的 template.php 文件中?
我使用这个模板系统 http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html
i have a little problem that i dont know what to do with.
i have a template with
- header
- content
- sidebar
- footer
on all my page the only thing that need to change is the content, so how can i pass data to my sidebar/footer
do i need to make a controller? or do i need to make a library and load it in my template.php file?
i use this template system
http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您的具体模板库,但我确实知道,通常这是通过在其他视图中嵌套视图来完成的,并且只要将数据加载到初始视图中,它也会传播到嵌套视图。
没有模板库的示例
控制器函数
first_view
在此实例中,加载到
first_view
中的$data
传播到 <代码>页眉、侧边栏
和页脚
。因此,您可以在任何这些视图中使用
$some_var
或$another_var
。更新
全局将数据加载到视图中的另一种方法是使用此函数
,其中
$data
是您的视图数据,此语句就在您之前加载模板应该允许在模板加载的任何视图中访问所有这些数据。虽然这是一种霰弹枪方法,但这是 您选择的模板库。I am not sure about your specific Template Library, but I do know that generally this is done by nesting views inside other views, and as long as the data is loaded into the initial view, it propagates to nested views as well.
Example without Template library
Controller function
first_view
In this instance, the
$data
that is loaded intofirst_view
propagates toheader
,sidebar
,andfooter
.So you can use
$some_var
or$another_var
in any of these views.UPDATE
Another way you can load data in to your views globally is with this function
Where
$data
is your view data, this statement just before you load your template should allow all of this data to be accessed in any view loaded by the template. While this is a shotgun approach, it is the suggested way to do this by your chosen template library.如果您只更改内容,则无需为页眉、侧边栏或页脚设置区域 - 只需将其内容添加到主模板文件中即可。
但是,如果您很少需要更改这些区域的内容,我将为这些区域创建“默认”视图,并加载到每个控制器构造函数中,如下所示:
然后您可以扩展这些默认区域视图或在每个控制器上覆盖它们方法基础(请参阅您的库的文档以了解如何操作)。
If you will only ever change content, then there is no need to set up regions for your header, sidebar or footer - just add their contents to your main template file.
However if you will infrequently need to change the content of these regions, I would create "default" views for these regions, and load in each controller constructor, like thus:
You can then either extend these default region views or overwrite them on a per method basis (refer to the documentation of your library to find out how).