使用smarty与codeignitor
问题描述:
我想使用codeigniter和smarty together.i.e。我想使用html文件,而不是codeigniter的.tpl.php文件作为smarty。这是可能的,我怎么可以这样做。我已经搜索了很多,并找到一些例子,但没有一些工作,我需要。
I wants to use codeigniter and smarty together.i.e. I wants to use html files instead of .tpl.php files of codeigniter as of smarty. Is this possible or how can I do this.I have searched a lot and find some examples but none of some works as required by me.
答
您应该创建一个库 Smarty_tpl.php
:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
//smarty class
require BASEPATH . "../../smarty/libs/Smarty.class.php";
class Smarty_tpl extends Smarty {
function __construct(){
parent::__construct();
$smarty_dir = BASEPATH . "../../smarty/libs/";
$this->setTemplateDir(APPPATH."views/templates");
$this->setCompileDir(APPPATH."views/templates_c");
$this->setCacheDir(APPPATH."views/cache");
$this->setConfigDir(APPPATH."views/config");
$this->setPluginsDir(array("$smarty_dir/plugins","$smarty_dir/sysplugins/"));
$this->compile_check= true;
$this->force_compile= true;
$this->caching= true;
$this->cache_lifetime= 86400;
}
}
其使用方式:
$this->load->library("Smarty_tpl");
$this->smarty_tpl->display("...");