用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2654|回复: 2
收起左侧

[HELP] CI包含公共模版的实现

[复制链接]
发表于 2013-4-6 17:36:50 | 显示全部楼层 |阅读模式
纠结坏了
瞎折腾的,通过model来实现
不过感觉这么一来好像还没有原始那种直接load->view()简单,知道的帮回下啊,万分感谢

入口文件
PHP复制代码
 
<?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复制代码
 
<?php
class Page_model extends CI_Model{
            function __construct()
            {
                       parent::__construct();
          }
        function header()
        {
                $this->load->view('header');
        }
        function footer()
        {
                $this->load->view('footer');
        }
}
 
复制代码


模版文件

HTML复制代码
 
 
<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>
 
复制代码

发表于 2013-4-8 13:10:00 | 显示全部楼层
这个能解决什么问题?
什么是公共模板?
发表于 2013-4-9 13:11:08 | 显示全部楼层

本版积分规则