ci中使用smarty

<p>d</p>

<?php defined('BASEPATH') or die('Access restricted!');
/*
* 作者:晉勇
*/
require(APPPATH.'libraries/smarty/Smarty.class.php');
class Cismarty extends Smarty
{
public $ext = 'tpl';
public $dir = '';
public $layout = 'layout/main';
/**
* 構造函數
*
* @access public
* @param array/string $template_dir
* @return obj smarty obj
*/
public function __construct($template_dir = '', $compile_dir = '', $config_dir = '', $cache_dir = '')
{
$this->Smarty();
if(is_array($template_dir)){
foreach ($template_dir as $key => $value) {
$this->$key = $value;
}
}
else {
$this->cache_dir = $cache_dir ? $cache_dir : BASEPATH . 'cache/';
$this->template_dir = $template_dir ? $template_dir : APPPATH . 'views/';
$this->compile_dir = $compile_dir ? $compile_dir : APPPATH . 'tpl_c/';
$this->compile_check = true;
$this->debugging = false; //debug模式
$this->caching = 0; //啟用緩存
$this->cache_lefetime= 6000;//緩存時間s
$this->left_delimiter= '<!--{';
$this->right_delimiter= '}-->';
}
}

/**
* 顯示輸出頁面
* @access public
* @return string
*/
public function show($tpl){
$this->assign('jsFiles',$this->getJsHtml());
$this->assign('jsFiles1',$this->getJsHtml(1));
$this->assign('LAYOUT', $this->dir ? $this->dir.'/'.$tpl.'.'.$this->ext : $tpl.'.'.$this->ext);
$this->display($this->layout.'.'.$this->ext);
}
/**
* 添加一個CSS文件包含
* @param string $file 文件名
* @access public
* @return void
*/
public function addCss($file) {
if (strpos($file,'/')==false) {
$file = config_item('css') . $file;
}
$GLOBALS['cssFiles'][$file] = $file;
}
/**
* 添加一個JS文件包含
* @param string $file 文件名
* @access public
* @return void
*/
public function addJs($file,$btm=NULL) {
if (strpos($file,'/')==false) {
$file = config_item('js') . $file;
}
if ($btm==NULL) {
$GLOBALS['jsfiles'][$file] = $file;
}
else {
$GLOBALS['jsbtmfiles'][$file] = $file;
}
}
/**
* 取生成的包含JS HTML
* @access public
* @return string
*/
public function getJsHtml($btm=NULL) {
$html = '';
if (!$GLOBALS['jsfiles']) {
return;
}
$jsFile = $btm?'jsbtmfiles':'jsfiles';
if (@$GLOBALS[$jsFile]) {
foreach ($GLOBALS[$jsFile] as $value) {
$html .= $this->jsInclude($value,true)."\n";
}
return $html;
}
else {
return ;
}
}
/**
* 添加html標簽
* @param string $tag 標簽名
* @param mixed $attribute 屬性
* @param string $content 內容
* @return string
*/
public function addTag($tag, $attribute = NULL, $content = NULL) {
$this->js();
$html = '';
$tag = strtolower($tag);
$html .= '<'.$tag;
if ($attribute!=NULL) {
if (is_array($attribute)) {
foreach ($attribute as $key=>$value) {
$html .= ' '.strtolower($key).'="'.$value.'"';
}
}
else {
$html .= ' '.$attribute;
}
}
if ($content) {
$html .= '>'.$content.'</'.$tag.'>';
}
else {
$html .= ' />';
}
$this->output .= $html;
return $html;
}
/**
* 添加html文本
* @param string $content 內容
* @return string
*/
public function addText($content) {
$this->js();
$content = htmlentities($content);
$this->output .= $content;
return $content;
}
/**
* 添加js代碼
* @param string $jscode js代碼
* @param bool $end 是否關閉js 代碼塊
* @return void
*/
public function js($jscode = NULL, $end = false) {
if (!$this->inJsArea && $jscode) {
$this->output .= "\n<mce:script language='JavaScript' type='text/javascript'><!--
\n//<!--[CDATA[\n
";
$this->inJsArea = true;
}
if ($jscode==NULL && $this->inJsArea==true) {
$this->output .= "\n//]]-->\n
// --></mce:script>\n
";
$this->inJsArea = false;
}
else {
$this->output .= "\t$jscode\n";
if ($end) {
$this->js();
}
}
return;
}
/**
* 添加js提示代碼
* @param string $message 提示內容
* @param bool $end 是否關閉js 代碼塊
* @return void
*/
public function jsAlert($message, $end = false) {
$this->js('alert("' . strtr($message, '"', '\\"') . '");', $end);
}
/**
* 添加js文件包含
* @param string $fileName 文件名
* @param bool $defer 是否添加defer標記
* @return string
*/
public function jsInclude($fileName,$return = false, $defer = false) {
if (!$return) {
$this->js();
}
$html = '<mce:script language="JavaScript" type="text/javascript" src="'
. $fileName . '" mce_src="'
. $fileName . '"' . ( ($defer) ? ' defer' : '' )
. '></mce:script>';
if (!$return) {
$this->output .= $html;
}
else {
return $html;
}
}
/**
* 添加css文件包含
* @param string $fileName 文件名
* @return string
*/
public function cssInclude($fileName,$return = false) {
if (!$return) {
$this->js();
}
$html = '<LINK href="' . $fileName . '" mce_href="' . $fileName . '" rel=stylesheet>' . chr(13);
if (!$return) {
$this->output .= $html;
}
else {
return $html;
}
}
/**
* 輸出html內容
* @param bool $print 是否直接輸出,可選,默認返回
* @return void
*/
public function output($print = false) {
$this->js();
if ($print) {
echo $this->output;
$this->output = '';
return;
}
else {
$output = $this->output;
$this->output = '';
return $output;
}
}
}
?>

dd

打開配置文件(config/autoload.php)

$autoload['libraries'] = array('cismarty');//加入cismarty

這樣在所有應用中,都可以使用$this->cismarty來調用smarty實例了。

Cismarty類已經在原有的smarty::display基礎上做了小的改動,已經支持layout功能

默認加載view/layout/main.tpl作為布局文件。

可以通過$this->cismarty->layout = "xxxx"來更改

來源?http://blog.csdn.net/a600423444/archive/2010/09/18/5892726.aspx

轉載于:https://www.cnblogs.com/xwblog/archive/2011/05/02/2034263.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378457.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378457.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378457.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

kinect中psi是什么_PSI的完整形式是什么?

kinect中psi是什么PSI&#xff1a;每平方英寸磅/國際人口服務 (PSI: Pound per Square Inch / Population Services International) 1)PSI&#xff1a;每平方英寸磅 (1) PSI: Pound per Square Inch) PSI is an abbreviation of Pound per Square Inch. Pound per Square Inch …

jupyter notebook指定工作目錄

【1】打開Anaconda Navigator 打開Anaconda Navigator&#xff0c;點擊左側Environments&#xff0c;點擊base(root)->open Terminal 【2】輸入指令jupyter notebook --generate-config 按下回車鍵&#xff0c;彈出config所在位置。 以VS Code打開文件 【3】修改第26…

四、纖維素纖維使用P-N系阻燃劑協同作用的原理?

纖維素纖維使用P-N系阻燃劑協同作用的原理? 收集資料階段 某些含氮、磷化合物可以增強化合物的阻燃性,原因就是磷、氮在反應過程中形成含 N-P 鍵的中間體,可以改善羰基反應活性和磷酰化速率,進而提高成炭率;另一個重要的原因是氮化合物可以延緩凝聚相中含磷化合物的會揮發…

oracle tns 連接關閉,ORA-12537 TNS:連接關閉

今天遇到&#xff1a;ORA-12537 TNS&#xff1a;連接關閉&#xff0c;監聽正常&#xff0c;集群正常&#xff0c;數據庫正常&#xff0c;查了一下才發現問題。LISTENER日志報錯TNS-12546: TNS:permission deniedTNS-12560: TNS:protocol adapter errorTNS-00516: Permission de…

多模態大模型:關于RLHF那些事兒

Overview 多模態大模型關于RLHF的代表性文章一、LLaVA-RLHF二、RLHF-V三、SILKIE多模態大模型關于RLHF的代表性文章 一、LLaVA-RLHF 題目: ALIGNING LARGE MULTIMODAL MODELS WITH FACTUALLY AUGMENTED RLHF 機構:UC伯克利 論文: https://arxiv.org/pdf/2309.14525.pdf 代碼…

c# 整數類型轉byte_C#中數據類型的整數類型

c# 整數類型轉byteHere is the list of the built-in integral types of data types in C#, sbyte, byte, char, short, ushort, int, uint, long and ulong 這是C&#xff03;&#xff0c; sbyte &#xff0c; byte &#xff0c; char &#xff0c; short &#xff0c; ushort…

COM+組件注冊方法

COM組件注冊方法 有兩種方式注冊組件&#xff1a;一種是調用regsvr32.exe&#xff1a;例如我們運行regsvr32.exe c:\test.dll來注冊位于C:盤根目錄下的test.dll。另外一種是在MTS&#xff08;微軟事務服務器&#xff09;中注冊。MTS是值得推薦的&#xff0c;因為它具有下列優點…

【智能車Code review】—曲率計算、最小二乘法擬合

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 系列文章 【智能車Code review】—曲率計算、最小二乘法擬合 【智能車Code review】——坡道圖像與控制處理 【智能車Code re…

五、“嵌段共聚醚酯型”易去污整理劑的結構特點及對織物服用性的影響?

“嵌段共聚醚酯型”易去污整理劑的結構特點及對織物服用性的影響? 收集資料階段 嵌段共聚醚酯型易去污整理劑(簡稱聚醚酯)是滌綸最早的一種耐久性易去污劑,其商品名稱為Permalose T,由英國ICI公司生產,它能使滌綸及其混紡織物具有優良的易去污、抗濕再沾污和抗靜電性能。…

linux服務器指示燈,【轉】明明白白你的Linux服務器——故障篇 | 旺旺知識庫

在Linux/unix服務器的維護過程中&#xff0c;遇到各種各樣的問題&#xff1b;有的嚴重&#xff0c;有的很好解決&#xff0c;有的解決過程我就記錄下來與大家分享下&#xff0c;希望能給大家帶來幫助。故障一、今天早上來的第一件事&#xff0c;就是檢查昨天晚上剛剛重新安裝的…

構件圖(Component Diagram)—UML圖(八)

構件圖是顯示代碼自身結構的實現級別的圖表。構件圖由諸如源代碼文件、二進制代碼文件、可執行文件或動態鏈接庫 (DLL) 這樣的構件構成&#xff0c;并通過依賴關系相連接 下面這張圖介紹了構件圖的基本內容&#xff1a; 下面這張圖是個構件圖的實例&#xff1a; 轉載于:https:/…

GAE work

https://appengine.google.com/ can visit in Home, but cannot visit in Office.Download a java SDK for GAE, will write something here.轉載于:https://www.cnblogs.com/cnyao/archive/2011/05/05/2038161.html

二進制文件簽名_二進制數的簽名表示

二進制文件簽名Prerequisite: Number systems 先決條件&#xff1a; 數字系統 Until now, we have only talked about positive numbers and have already discussed their mathematical operations. But there also exists negative numbers in the number system, in this a…

【智能車Code review】——坡道圖像與控制處理

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 系列文章 【智能車Code review】—曲率計算、最小二乘法擬合 【智能車Code review】——坡道圖像與控制處理 【智能車Code re…

六、解釋紅外線紡織品的保健、保暖作用?

解釋紅外線紡織品的保健、保暖作用&#xff1f; 收集資料階段 人體既是遠紅外的輻射源又能吸收遠紅外輻射。由于人體60&#xff05;&#xff5e;70&#xff05;為水?故人體對紅外輻射吸收近似于水&#xff0c;人體組織所擁有的特定振動頻率和回轉周波數與人體組織中的O&…

linux yum命令作用,YUM命令使用示例

YUM或Yellowdog Updater Modified是管理rpm包的前端工具。 它用于通過命令行界面或使用圖形模式來安裝&#xff0c;刪除&#xff0c;更新和收集有關rpm軟件包的信息。 使用YUM的主要優點是&#xff0c;它解決了rpm包的所有依賴關系&#xff0c;并將它們與包一起安裝。下面讓我們…

PySide開發MySql遠程備份工具

MySql數據庫安裝在機房&#xff0c;而工作人員日常辦公的地方距離機房有段距離&#xff0c;且不在同一樓層。出入機房不是很方便。就想著能否給這些人員開發一個圖形化的備份MySql數據庫的小工具&#xff1f;使用組件如下&#xff1a;(1)Python(2)PySide(3)mysqldump其實mysql已…

HadoopSourceAnalyse --- Nodemanager Container request handler

Overview Container 是Hadoop中運行任務的地方&#xff0c;當Resourcemanager收到一任務請求后&#xff0c;會向nodemanager 請求一個Container 來運行ApplicationMaster&#xff0c; ApplicationMaster運行起來之后&#xff0c;會繼續向Resourcemanager請求新的container來運行…

數據結構 二叉樹的存儲結構_線程二叉樹| 數據結構

數據結構 二叉樹的存儲結構線程二叉樹 (Threaded Binary Tree ) A binary tree can be represented by using array representation or linked list representation. When a binary tree is represented using linked list representation. If any node is not having a child …

七、有機硅柔軟劑在不同發展階段分子結構特征及主要解決的問題?

有機硅柔軟劑在不同發展階段分子結構特征及主要解決的問題? 收集資料階段 聚有機硅氧烷具有低表面能、優良的潤滑性、熱穩定性和疏水性。從分子層面分析,經聚有機硅氧烷處理的織物,其柔軟性來自硅氧烷骨架中 Si—O—Si鍵的 360自由旋轉及甲基之間的低相互作用。因此,聚有機…