简体   繁体   English

Codeigniter加载多个模板

[英]Codeigniter loading multiple templates

I'm using this Template library for Codeigniter. 我正在将此模板库用于Codeigniter。

I can't quite figure out how to use his example, advanced use #3, to load multiple templates. 我不太清楚如何使用他的示例(高级用法#3)来加载多个模板。 I feel like the loading of a 2nd template is missing from his load_main() function below: 我感觉下面的load_main()函数缺少第二个模板的加载:

function load_main($view = '', $view_data = array(), $return = FALSE)
{
$this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
$this->load('template', $view, $view_data, $return);
    //shouldn't this be there?=> $this->load('template2', $view, $view_data, $return);
}

Am I correct? 我对么? And if so, can you give some hints on how the controller and view files would look? 如果是这样,您能否提供一些有关控制器和视图文件外观的提示?

Here's what the author has for the controller: 这是作者对控制器的要求:

$this->template->set('nav', 'About');
$this->template->set('title', 'About me');
$this->template->load_main('about');  

And the template view: 和模板视图:

<html>
<body>
    <div id="contents"><?= $contents ?></div>
    <div id="footer">Copyright 2008</div>
<ul class="navigation">
<?php foreach($nav_list  as $i => $nav_item): ?>
    <li class="<?= ($nav == $nav_item ? 'selected' : '')?>">
        <?= anchor($nav_item, $nav_item) ?>
    </li>
<?php endforeach ?>
</ul>
</body>
</html> 

I don't think it's missing something, but it's a bit unclear how it does work... 我不认为它缺少什么,但是还不清楚它是如何工作的...

function load_main($view = '', $view_data = array(), $return = FALSE)
{
    $this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
    $this->load('template', $view, $view_data, $return);
}

So this method uses the "template" template and sets some nav stuff. 因此,此方法使用“模板”模板并设置一些导航项。 $this->template->load_main('test'); would load views/test.php using the "template" template. 将使用“模板”模板加载views / test.php。

So to use a different template, create a new load method in your template file (and template, obviously) 因此,要使用其他模板,请在您的模板文件(显然是模板)中创建新的加载方法

function load_radical_template($view = '', $view_data = array(), $return = FALSE)
{
    $this->load('radical_template', $view, $view_data, $return);
}

Now $this->template->load_radical_template('test'); 现在$this->template->load_radical_template('test'); would load views/test.php using the "radical_template" template. 将使用“ radical_template”模板加载views / test.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM