成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? CodeIgniter集成smarty的方法詳解
全站頭部文字 我要出現(xiàn)在這里
CodeIgniter集成smarty的方法詳解 742 2024-02-01   

本文實例講述了CodeIgniter集成smarty的方法。分享給大家供大家參考,具體步驟如下:

1.下載smarty

解壓到ci的libraries目錄 如:

ci/application/libraries/Smarty-2.6.20

2.編寫Mysmarty.php 自己的類庫文件

代碼如下:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "Smarty-2.6.20/libs/Smarty.class.php";
/**
* @file system/application/libraries/Mysmarty.php
*/
class Mysmarty extends Smarty
{
  function Mysmarty()
  {
    $this->Smarty();
    $config =& get_config();
    // absolute path prevents "template not found" errors
    $this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir'] : BASEPATH . 'application/views/');
    $this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir'] : BASEPATH . 'cache/'); 
    //use CI's cache folder
    if (function_exists('site_url')) {
      // URL helper required
      $this->assign("site_url", site_url()); // so we can get the full path to CI easily
    }
  }
  /**
  * @param $resource_name string
  * @param $params array holds params that will be passed to the template
  * @desc loads the template
  */
  function view($resource_name, $params = array())  {
    if (strpos($resource_name, '.') === false) {
      $resource_name .= '.html';
    }
    if (is_array($params) && count($params)) {
      foreach ($params as $key => $value) {
        $this->assign($key, $value);
      }
    }
    // check if the template file exists.
    if (!is_file($this->template_dir . $resource_name)) {
      show_error("template: [$resource_name] cannot be found.");
    }
    return parent::display($resource_name);
  }
} // END class smarty_library
?>

3.在autoload.php讓ci自動加載smarty

$autoload['libraries'] = array('database', 'mysmarty');

或者 使用模板時再自己加載smarty

$this->load->library("mysmarty");

4.smarty變量賦值 display模板

$this->mysmarty->assign('test', 'Hello World.');
$this->mysmarty->view('smarty');

注:images css 等外部資源文件 放在ci系統(tǒng)文件夾外 網(wǎng)站根目錄下

最好用:

$this->load->helper('url');

base_url()來訪問:

base_url()."images/xxx.jpg"

不要放到system里

補充:小編在這里推薦一款本站的php格式化美化的排版工具幫助大家在以后的PHP程序設(shè)計中進行代碼排版:

php代碼在線格式化美化工具:

http://tools.gimoo.net/code/phpformat

另外,由于php屬于C語言風(fēng)格,因此下面這款工具同樣可以實現(xiàn)php代碼的格式化:

C語言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
http://tools.gimoo.net/code/ccode_html_css_json

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

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



主站蜘蛛池模板: 王者图片| 那些女人 电影| 女公安毛片免费观看| 没有下巴| 大场久美子| 佳片有约| 77316电影| 孙源| yumiko| 四川影视文艺频道| 电影壮志凌云女版满天星法版在线看| 韩国青草视频| 圆的认识评课| 男同性恋免费视频| 希崎| 甜蜜高潮 第一季 电视剧| 林子祥电影| 日本无遮挡吸乳免费视频| 电影继父| 隐藏的歌手第一季中国版| 浙江卫视节目表电视猫| 我姨| 儿媳妇电视剧在线观看| 麻花影业| 村暖花开| 色在线视频| 色女孩视频| 新红楼梦2010在线观看免费| 极地重生 电影| 写我的好朋友二年级作文| 改朝换代| someonelikeyou歌词中文翻译| 美女游泳| 乡村女教师 电影| 杨紫和肖战演的电视剧是什么| 性欲满载| 妈妈的朋友未删减版| 美女中刀| 天国遥遥| x档案第二季| 4人免费剧本及答案|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103