valkhan/codeigniter-template

支持Codeigniter的定制模板

dev-master 2018-09-05 13:12 UTC

This package is auto-updated.

Last update: 2024-09-23 03:04:42 UTC


README

此分支是为了与Codeigniter框架兼容而创建的,更多详细信息请查看Rael创建的原始存储库。

将根据我对原始类和以下添加的功能的理解提供类支持

1 - dieOnError - 启用/禁用由于找不到块和变量而触发的某些错误。

2 - caseInsensitiveVars - 启用/禁用填充变量/块时忽略其原始大小写。

3 - CodeIgniter - 关于与Codeigniter框架一起使用和安装的疑问以及相关更改。

4 - 函数:blockArr, varsArr, addArray - 我已添加这些函数,也可以提供对这些函数的支持。

历史记录

2016年7月16日 - v2.3 - 生成与CodeIgniter兼容的初始包。

下载

要下载库,请选择以下选项

  • 使用git克隆存储库(git clone git@github.com:raelgc/template.git)或
  • 下载.zip文件

许可证

我把Rael的话当作自己的话

此库的许可证受LGPL许可的约束。也就是说,您可以使用它作为库,即使在商业项目中也可以。

但请记住做一个合法的人,并在必要时发送回修改、纠正或改进。

必要条件

需要使用PHP 5.3或更高版本的任何版本。

安装和使用

1 - 在CodeIgniter项目根目录中解压缩.zip文件

2 - 使用Codeigniter的load方法加载库

3 - 配置初始参数并根据需要使用类(以下有示例)

PHP文件

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Tests extends CI_Controller {
public function teste() {
        //-- Desired config
        $config = array(
            'dieonerror' => false, //-- Disables some errors
            'accurate' => false, //-- Disable accurate
            'caseinsensitivevars' => true, //-- Enable case sensitive sets of variables and blocks
            /*'filename' => VIEWPATH.'tests/tests_template_valkhan.html'*/ //-- Load file (I do not recommend using this argument as it can break script execution if file does not exist, see how to manually load file below)
            );
        //-- Load library
        $this->load->library(
            'template', //-- Library name
            $config, //-- Config array
            'myTpl' //-- Desired alias
            );
        //-- Manually load template file: use dot as first argument
        $this->myTpl->addFile('.',VIEWPATH.'tests/tests_template_valkhan.html'); 
        //-- Folder data to output 
        $folders = array(
            'disk1' => array(
                'musics'  => array('rock','symphonic metal','soundtrack'),
                'images'  => array('wallpapers','family')
                ),  
            'disk2' => array(
                'programs'  => array('sublime_text','xampp'),
                'games'  => array('watch_dogs','assassins_creed','nba 2k16')
                )
            );

        //-- Old fashion way of populating the template:
        foreach($folders as $nest1 => $next){
            foreach($next as $nest2 => $next2){
                $this->myTpl->NAME_NEST2 = $nest2;
                foreach($next2 as $nest3){
                    $this->myTpl->nAmE_nEsT1 = $nest1;
                    $this->myTpl->NAME_nest3 = $nest3;
                    $this->myTpl->block('NEST3'); 
                }
                $this->myTpl->block('NesT2'); 
            }
            $this->myTpl->nAmE_nEsT1 = $nest1;
            $this->myTpl->block('nest1'); 
        }
        
        //-- An anxiliary method for single blocks or variables setters
        $vehicles = array(
            array('name' => 'Car', 'type' => 'land'),
            array('name' => 'Motorbike', 'type' => 'land'),
            array('name' => 'Truck', 'type' => 'land'),
            array('name' => 'Boat', 'type' => 'sea'),
            array('name' => 'Battleship', 'type' => 'sea'),
            array('name' => 'Airplane', 'type' => 'air'),
            array('name' => 'Rocket', 'type' => 'space')
            );

        $this->myTpl->title = 'Template example on CI';
        $this->myTpl->addArray($vehicles,'vehicles');
        $this->myTpl->show();
    }
}

HTML文件

<!DOCTYPE html>
<html>
<head>
    <title>{TITLE}</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        fleft{
            float: left;
        }
    </style>
</head>
<body>
    <h1>Folders</h1>
    <!-- BEGIN NEST1 -->
    /{NAME_NEST1}<br>
        <!-- BEGIN NEST2 -->
        /{NAME_NEST1}/{NAME_NEST2}<br>
            <!-- BEGIN NEST3 -->
            /{NAME_NEST1}/{NAME_NEST2}/{NAME_NEST3}<br>
            <!-- END NEST3 -->
        <!-- END NEST2 -->
    <br>    
    <!-- END NEST1 -->
    <hr>
    <h1>Vehicles</h1>
    <!-- BEGIN VEHICLES -->
    <div class="fleft">{NAME} / {TYPE}</div>
    <!-- END VEHICLES -->
    <hr>
    <!-- BEGIN FINALLYEXAMPLE -->
    {SOMEVAR}
    <!-- END FINALLYEXAMPLE -->
    Nothing sent to 'FINALLYEXAMPLE' block.
    <!-- FINALLY -->
</body>
</html>

有关类本身的功能的任何疑问,请参阅Rael在其存储库或网站http://raelcunha.com/template/上留下的示例。