有关视图的问题

发布于 2024-10-28 10:53:01 字数 199 浏览 0 评论 0原文

我对 Codeigniter 中的视图有一些疑问。

如何构建我的设计以及稍后如何返回它?我想构建我的页眉、主要内容和菜单、页脚等。

构建一个设计,然后将其复制到我创建的每个新视图中,这感觉不是一个好的解决方案。如果我更改页脚中的某些内容,则更改将对整个网站生效。

有没有人有任何好的指南的链接,如何充分利用视图或在这里以良好的方式解释。

I have some questions about View in Codeigniter.

How do I build up my design and how do I return it later? I would like to build my header, main content and menu, footer and more.

To build up a design and then copy it into every new view I created does not feel like a good solution. If I change something in the footer, the change takes effect for the entire website.

Does anyone have any link to any good guide how to make the best use out of view or explain in a good way here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

天涯离梦残月幽梦 2024-11-04 10:53:01

你的感觉是对的,这根本不是一个好主意。这就是为什么大多数人将某种模板系统与他们的视图结合使用的原因。

我曾经使用过这个库: http://williamsconcepts.com/ci/codeigniter/libraries/template / (以前是这样,因为我不再用 CI 编写太多代码)

它从来没有给我带来麻烦,而且设置起来非常容易。

Your feeling is right, it's not a good idea at all. That's why most people use some kind of templating system in conjunction with their View.

I used to use this library : http://williamsconcepts.com/ci/codeigniter/libraries/template/ (used to, because I don't code much in CI anymore)

It's never given me trouble and it's pretty easy to setup.

清引 2024-11-04 10:53:01

您应该将页眉、页脚、菜单等设置为各自的视图。这样,当您想要更改(例如页脚)时,您可以编辑该视图,然后使用该视图的每个控制器都会更新。

有关多个视图文件的详细信息,请参阅 CodeIgniter 文档

You should make your header, footer, menu, etc. each their own view. That way when you want to change, say, the footer, you edit that view, and then each controller that uses that view will be updated.

See the CodeIgniter docs for more info on multiple view files.

不爱素颜 2024-11-04 10:53:01

这里有两个半选项(假设您不想安装某种插件)。

选项 1 是在您的视图中使用 load->view('header'); ?> 等等。

选项 2 是在控制器中重写 output 函数,该函数接受一个参数(页面的内容)并从那里对其进行操作(添加视图等)。
选项 2.5 是重写基本 CI_Controller 并实现与上面相同的 output 函数的标准重写。

在执行选项 2/2.5 之前检查输出类的文档;在回显之前,您需要将输出内容设置为 null 或空字符串,否则内容将出现两次。

You have two-and-a-half options here (assuming you don't wish to install a plugin of some kind).

Option 1 is to, in your views, use <?php $this->load->view('header'); ?> and so on.

Option 2 is to, in your controller, override the output function, which takes one argument (the content of the page) and manipulate it from there (adding views and whatnot).
Option 2.5 is to override the base CI_Controller and implement a standard override of the output function same as above.

Check the documentation on the output class before doing option 2/2.5; you will need to set the output content to null or an empty string before echoing, or the content will appear twice.

默嘫て 2024-11-04 10:53:01

从控制器出来

   if($query->result())
{
    **$data['blog']** = $query->result();
}
    $data['title'] = 'LemonRose';
    $data['content'] = 'home/home_content'; //this is the content section, a separate view from header and footer
    //$this->output->cache(60);
    **$this->load->view('template1', $data);** 
}

注意 template1

模板 1 (这是整个页面)

$this->load->view('tops/home');
$this->load->view($content); $content is the $data['content'] from above
$this->load->view('bottoms/main_home');

然后内容部分 (home/home_content) 将有一个地方来接收 $data[blog]

foreach (**$blog** as $row){ //controller main

$row->title = ucwords($row->title); //more code goes below

Coming out of the controller

   if($query->result())
{
    **$data['blog']** = $query->result();
}
    $data['title'] = 'LemonRose';
    $data['content'] = 'home/home_content'; //this is the content section, a separate view from header and footer
    //$this->output->cache(60);
    **$this->load->view('template1', $data);** 
}

Note template1

Template 1 (this is the entire page)

$this->load->view('tops/home');
$this->load->view($content); $content is the $data['content'] from above
$this->load->view('bottoms/main_home');

Then the content section (home/home_content) would have a place to receive the $data[blog]

foreach (**$blog** as $row){ //controller main

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