Nop 发表于 2013-4-6 17:36:50

CI包含公共模版的实现

纠结坏了
瞎折腾的,通过model来实现
不过感觉这么一来好像还没有原始那种直接load->view()简单,知道的帮回下啊,万分感谢

入口文件

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
      public function __construct()
      {
                parent::__construct();
                $this->load->model('Page_model');
      }
      public function index()
      {
                $this->load->view('welcome_message.php');
      }

}

捣鼓的个模型

<?php
class Page_model extends CI_Model{
            function __construct()
            {
                     parent::__construct();
          }
      function header()
      {
                $this->load->view('header');
      }
      function footer()
      {
                $this->load->view('footer');
      }
}


模版文件



<div id="container">
      <?php $this->Page_model->header();?>
      <h1>Welcome to CodeIgniter!</h1>

      <div id="body">
                <p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

                <p>If you would like to edit this page you'll find it located at:</p>
                <code>application/views/welcome_message.php</code>

                <p>The corresponding controller for this page is found at:</p>
                <code>application/controllers/welcome.php</code>

                <p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
      </div>

      <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
      <?php $this->Page_model->footer();?>
</div>

</body>
</html>

Hex 发表于 2013-4-8 13:10:00

这个能解决什么问题?
什么是公共模板?

paperen 发表于 2013-4-9 13:11:08

你这是layout的概念吧? http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=14894
页: [1]
查看完整版本: CI包含公共模版的实现