选择是否向现有的Codeigner应用程序添加模板库


Choosing whether to add or not a templating library to an existent Codeigniter app

因此,在我的应用程序的开发过程中,我已经达到了一个特定的点,其中有以下文件夹结构:

views/
     includes/{header.php, template.php, footer.php}
     home.php
     xyz.php
     ... 

并以这种方式加载视图

controller.php

    $data['lists'] = $lists;
    $data['view'] = 'home';
    $this->load->view('includes/template', $data);

template.php

<?php
    $this->lang->load('common');
    if($view == 'videoPage') 
    {
        $header['title']       = $data['title'].' - XYZ.com ';
        $header['description'] = $data['description'];
        $header['keywords']    = implode(', ',$data['tags']);
        $header['canonical']   = $data['canonical'];
        $this->load->view('includes/header', $header);
    }
    elseif (($view == "searchsPage") || ($view == 'tagsPage'))
    {
        $header['title'] = $query.' - XYZ.com ';
        $this->load->view('includes/header', $header);
    }
    else
    {
        $this->load->view('includes/header');
    }
?>
    <div role="container">
        <?php
            if ( ! empty($data))
            {
                $this->load->view($view, $data);
                if(($view == 'searchsPage') OR ($view == 'tagsPage')):
                ?>
                ...SPECIFIC CODE HERE...
                <?php endif;
            }
            else
            {
                $this->load->view($view);
            }
        ?>
    </div>
<?php $this->load->view('includes/footer'); ?>

还有更多。。。

开始变得有点混乱,所以我想知道从http://getsparks.org/search(搜索"模板")还是只是对我使用的模板进行一些改进?还有其他想法吗?

我也开始自己实现库,但过了一段时间,它变得一团糟,然后改为现有库。具体来说,我使用了菲尔·斯特金图书馆,这是一个很好的图书馆。指向库的链接http://getsparks.org/packages/template/versions/HEAD/show.希望这能有所帮助。

制作自己的模板库并保持代码干燥。你不需要每次都插入页脚和页眉。此外,您还可以查看已编写的模板模型。

这里列出了一些Codeigniter模板库