代码点火器侧边栏

发布于 2024-10-15 06:32:56 字数 404 浏览 2 评论 0原文

我有一个小问题,我不知道该怎么办。

我的所有页面上都有一个带有

  • 标题
  • 内容
  • 侧边栏
  • 页脚

的模板,唯一需要更改的是内容,那么我如何将数据传递到我的侧边栏/页脚,

我需要制作一个控制器吗?或者我是否需要创建一个库并将其加载到我的 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 技术交流群。

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

发布评论

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

评论(2

悲凉≈ 2024-10-22 06:32:56

我不确定您的具体模板库,但我确实知道,通常这是通过在其他视图中嵌套视图来完成的,并且只要将数据加载到初始视图中,它也会传播到嵌套视图。

没有模板库的示例

控制器函数

function index() {

    $data['some_var']    = "some value";
    $data['another_var'] = "another value";

    $this->load->view('first_view',$data);
}

first_view

<? $this->load->view('header') ?>

<h1>Content</h1>

<? $this->load->view('sidebar') ?>
<? $this->load->view('footer') ?>

在此实例中,加载到 first_view 中的 $data 传播到 <代码>页眉、侧边栏页脚

因此,您可以在任何这些视图中使用 $some_var$another_var

更新

全局将数据加载到视图中的另一种方法是使用此函数

$this->load-vars($data); 

,其中 $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

function index() {

    $data['some_var']    = "some value";
    $data['another_var'] = "another value";

    $this->load->view('first_view',$data);
}

first_view

<? $this->load->view('header') ?>

<h1>Content</h1>

<? $this->load->view('sidebar') ?>
<? $this->load->view('footer') ?>

In this instance, the $data that is loaded into first_view propagates to header,sidebar,and footer.

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

$this->load-vars($data); 

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.

荒路情人 2024-10-22 06:32:56

如果您只更改内容,则无需为页眉、侧边栏或页脚设置区域 - 只需将其内容添加到主模板文件中即可。

但是,如果您很少需要更改这些区域的内容,我将为这些区域创建“默认”视图,并加载到每个控制器构造函数中,如下所示:

$this->template->write_view('header', 'default/header');
$this->template->write_view('sidebar', 'default/sidebar');
$this->template->write_view('footer', 'default/footer');

然后您可以扩展这些默认区域视图或在每个控制器上覆盖它们方法基础(请参阅您的库的文档以了解如何操作)。

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:

$this->template->write_view('header', 'default/header');
$this->template->write_view('sidebar', 'default/sidebar');
$this->template->write_view('footer', 'default/footer');

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).

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