2011-08-14 84 views
0

使用Template Library Here,我仍然对我应该存储页眉和页脚文件的位置以及它们是如何形成仍然有点困惑。模板大厦

控制器:

class Kowmanager extends CI_Controller { 

public function __construct() 
{ 
    $this->load->helper('url'); 
    $this->load->library('tank_auth'); 
    $this->load->library('template'); 
    parent::__construct(); 

} 

function index() 
{ 
    if (!$this->tank_auth->is_logged_in()) { 
     redirect('/auth/login/'); 
    } else { 
     $data['user_id'] = $this->tank_auth->get_user_id(); 
     $data['username'] = $this->tank_auth->get_username(); 
     $this->load->view('welcome', $data); 
    } 
} 

} 

/* End of file kowmanager.php */ 
/* Location: ./application/controllers/kowmanager.php */ 

我希望发生的是有页眉和页脚文件加载,然后还它必须在那里,因为有登录,它会加载活动模型并有登记等,而那些将拥有自己的内容,并将在页眉和页脚之间加载。

编辑:我只是困惑在哪里把页眉页脚文件

有没有人有任何想法?

+1

一些代码将是很好的。 –

+0

更新了新的内容,只是记住我正在使用的图书馆。 –

回答

1

如果我理解正确,你想加载页眉和页脚之间的视图?

我有同样的问题,最后想出了使用库来做渲染的想法。

我所做的就是创建一个文件libraries/render.php的东西,如:

class render 
{ 
    private $CI; 
    function __construct() 
    { 
     parent::__construct(); 
     $this->CI &= get_instance(); 
    } 
    function view ($activeView, $params, $title) 
    { 
     $this->CI->load->view('template/header.php', array('title'=>$title)); 
     $this->CI->load->view($activeView, $params); 
     $this->CI->load->view('template/footer.php', array('navbar'=>$this->RenderFooterNavBar())); 
    } 

    private function RenderFooterNavBar() 
    { 
     $bits = array('Home','About Us', 'Contact'); //You could get these from anywhere 
     return $this->CI->load->view('template/modules/footernavbar', array('bits'=>$bits), TRUE); //returns the rendered output of that view 
    } 
} 

随着文件如:
template/header.php

<html> 
<head> 
    <title><?php echo $title; ?></title> 
</head> 
<body> 

template/footer.php

</body> 
</html> 

template/modules/footernavbar

<ul> 
<?php 
foreach ($bits as $item) 
    echo "<li>$item</li>"; 
?> 
</ul> 

然后使用:

function index() 
{ 
    $this->render->view('post', $data, 'Blog Post'); 
} 

注意,这应该与任何模板系统工作,只是与你的模板系统使用捏捏load->view秒。如果你想从数据库中提取数据,这也是渲染页眉/页脚需要的数据的一种很好的方式,仅仅反映我用RenderFooterNavBar()函数做的事情。

希望帮助一些,
最大

+0

我已经从这里下载了模板系统http://getsparks.org/packages/template/show,但不知道我是否理解它 –