using smarty with codeigniter

亡梦爱人 提交于 2019-12-23 03:19:04

问题


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.


回答1:


You should create a library 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;
}
}

And its using:

$this->load->library("Smarty_tpl");
$this->smarty_tpl->display("...");



回答2:


There is built in templating library in codeigniter so why bother using smarty?



来源:https://stackoverflow.com/questions/10282605/using-smarty-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!