濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎DEMO示例

CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎DEMO示例

熱門(mén)標(biāo)簽:七魚(yú)外呼系統(tǒng)停用嗎 海南人工外呼系統(tǒng)有效果嗎 阿里云400電話申請(qǐng)加工單 地下城堡2圖九地圖標(biāo)注 保定crm外呼系統(tǒng)運(yùn)營(yíng)商 智能電話機(jī)器人排名前十名南京 西區(qū)企業(yè)怎么做地圖標(biāo)注入駐 九江外呼系統(tǒng) 抖音有個(gè)地圖標(biāo)注是什么意思

本文實(shí)例講述了CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎。分享給大家供大家參考,具體如下:

Smarty的模板機(jī)制很強(qiáng)大,一般情況下CI框架無(wú)需整合其他模板標(biāo)簽,因?yàn)镻HP本身就是一種標(biāo)簽,簡(jiǎn)單易用。Codeigniter整合Smarty教程(我用的都是最新版本)如下:

第一步:下載Codeigniter最新版本:CodeIgniter框架源碼
第二步:下載Smarty最新版本:Smarty引擎源碼
第三步:具體配置

我已將本人整合好的代碼上傳,有興趣的可以下載閱讀。Codeigniter框架整合Smarty引擎DEMO 。

1、準(zhǔn)備

將smarty拷貝到application/libraries下,然后再根目錄下下新建templates,templates_c,config,cache目錄,結(jié)構(gòu)如下:

2、修改入口文件

在入口文件index.php中新增:

define('ROOT', dirname(__FILE__));

3、新建CI_Smarty.php

在libraries文件下新建CI_Smarty.php,寫(xiě)如下代碼:

?php
/**
* =======================================
* Created by PK Technology.
* Author: ZhiHua_W
* Date: 2016/10/31 0031
* Time: 上午 9:16
* Project: CI整合
* Power: CI框架整合smarty
* =======================================
*/
defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH . 'libraries/smarty/Smarty.class.php');
class CI_Smarty extends Smarty
{
    public function __construct($template_dir = '', $compile_dir = '', $config_dir = '', $cache_dir = '')
    {
      parent::__construct();
      if (is_array($template_dir)) {
        foreach ($template_dir as $key => $value) {
          $this->$key = $value;
        }
      } else {
        //ROOT是Codeigniter在入口文件index.php定義的本web應(yīng)用的根目錄
        $this->template_dir = $template_dir ? $template_dir : ROOT . '/templates';
        $this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c';
        $this->config_dir = $config_dir ? $config_dir : ROOT . '/config';
        $this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache';
      }
    }
}

4、在controller中使用

在控制器Welcome.php中寫(xiě)入使用方法,代碼如下:

?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller
{
    /**
     * Welcome constructor.
     * 寫(xiě)入構(gòu)造函數(shù),引入CI_Smarty類文件
     */
    public function __construct()
    {
      parent::__construct();
      $this->load->library('CI_Smarty');
    }
    /**
     * smarty測(cè)試函數(shù)
     */
    public function test()
    {
      $this->ci_smarty->assign('test', 'smarty');
      $this->ci_smarty->display('test.tpl');
    }
}

5、創(chuàng)建模版試圖

在templates文件夾下創(chuàng)建test.tpl文件,寫(xiě)入如下代碼:

!DOCTYPE html>
html lang="en">
head>
  meta charset="UTF-8">
  title>Codeigniter整合Smarty測(cè)試/title>
/head>
body>
這是 {$test} 測(cè)試
/body>
/html>

6、訪問(wèn)

至此,我們整合完畢,訪問(wèn):http://localhost/Codeigniter_Smarty/index.php/Welcome/test即可看到測(cè)試結(jié)果。

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《ThinkPHP入門(mén)教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》

希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • CodeIgniter整合Smarty的方法詳解
  • CodeIgniter集成smarty的方法詳解
  • Codeigniter中集成smarty和adodb的方法
  • CodeIgniter中使用Smarty3基本配置
  • 讓codeigniter與swfupload整合的最佳解決方案
  • Codeigniter整合Tank Auth權(quán)限類庫(kù)詳解
  • CodeIgniter模板引擎使用實(shí)例
  • CodeIgniter使用phpcms模板引擎

標(biāo)簽:甘肅 昭通 遼陽(yáng) 九江 十堰 梅河口 涼山 韶關(guān)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎DEMO示例》,本文關(guān)鍵詞  CodeIgniter,框架,實(shí)現(xiàn),的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎DEMO示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于CodeIgniter框架實(shí)現(xiàn)的整合Smarty引擎DEMO示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    崇州市| 来凤县| 临城县| 武定县| 甘肃省| 大英县| 秭归县| 云安县| 四子王旗| 沽源县| 虞城县| 望奎县| 进贤县| 呼伦贝尔市| 横山县| 正定县| 永州市| 法库县| 禄丰县| 姜堰市| 竹北市| 教育| 镇江市| 闽侯县| 芦山县| 图木舒克市| 邵武市| 若尔盖县| 江孜县| 玉溪市| 尼玛县| 理塘县| 利辛县| 贡觉县| 繁昌县| 平塘县| 赤壁市| 汝南县| 安徽省| 化州市| 繁昌县|