【问题标题】:Include contents from one view to another in CodeIgniter在 CodeIgniter 中包含从一个视图到另一个视图的内容
【发布时间】:2011-11-18 11:23:14
【问题描述】:

我是 CodeIgniter 的新手,所以我在将内容从一个视图添加到另一个视图时遇到了一些问题。 我有三个视图的页眉、内容和页脚,我想将这些视图放在一个宽度为 960 像素的主容器中。

因为我是新人,所以期待一些简单的答案。

我的代码是这样的

public function index()
{
        $this->load->view('header');
        $this->load->view('content');
        $this->load->view('footer');            
}

谢谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    你需要这个。

    $output  = $this->load->view('header', 'your_data', true);
    $output .= $this->load->view('content', 'your_other_data', true);
    $output .= $this->load->view('footer', 'your_last_data', true);
    
    $this->output->set_output($output);
    

    了解更多Info

    【讨论】:

      【解决方案2】:

      只需调用主视图中的视图

        public function index()
          {
              $data['content']['title'] = 'title';
              $data['content']['body'] = 'body';
              $this->load->view('layout',$data);         
          }
      

      在views/layout.php中

      <div id="main_container">
          <?php
             $this->load->view('header',$content);
             $this->load->view('content',$content);
             $this->load->view('footer');  
          ?>
      </div>
      

      例如。在views/header.php中

      <title>.<?php echo $title;?></title>
      

      在views/content.php中

      <div id="main_body"><?php echo $body;?></div>
      

      【讨论】:

        【解决方案3】:
        function index()
        {
              $data['title']        ="Details";
              $this->load->view("headerview",$data);
              $data['batches']  =$this->detailsmodel->getname();
             $this->load->view('content',$data);
             $this->load->view("footerview");
        }
         // something similar to this ?          
        

        没有正确理解您的问题,简要说明您想要什么?这就是你要找的答案吗

        【讨论】:

        • 你为什么认为他有一个名为“view”的视图?
        • @RupeshPawar 抱歉,应该是内容
        猜你喜欢
        • 2011-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多