温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在CodeIgniter中对Smarty3进行配置

发布时间:2020-12-19 14:50:01 来源:亿速云 阅读:100 作者:Leah 栏目:开发技术

如何在CodeIgniter中对Smarty3进行配置?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

一、创建Smarty类库

1.将smarty的libs文件复制到libraries下(这里我重命名为smarty)
2.新建Cismarty.php文件。(符合文件规范,文件名的首字母和class名的首字母大写,但是控制器引用加载时,类名/文件名不需要大写)

Cismarty.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH . 'libraries/smarty/Smarty.class.php');
//CI,文件系统全用相对路径相对index.php所在的路径,url全部用绝对路径。
//BASEPATH    - The full server path to the "system" folder
//APPPATH    - The full server path to the "application" folder
class Cismarty extends Smarty
{
  public function __construct()
  {
 
    parent::__construct();
    $this->caching = false;
    $this->setTemplateDir(APPPATH . 'views/Smarty/templates'); //设定所有模板文件都需要放置的目录地址。
    $this->setConfigDir(APPPATH . 'views/Smarty/configs'); //设定用于存放模板特殊配置文件的目录,
    $this->setCacheDir(APPPATH . 'views/Smarty/cache'); //在启动缓存特性的情况下,这个属性所指定的目录中放置Smarty缓存的所有模板
    $this->setPluginsDir(APPPATH . 'views/Smarty/plugins'); //插件目录
    $this->setCompileDir(APPPATH . 'views/Smarty/templates_c'); //设定Smarty编译过的所有模板文件的存放目录地址
 
 
  }
 
}
 
?>

 在对应目录新建smarty的文件夹。templates,configs,cache,plugins,templates_c.

二、控制器文件

建立控制器文件paper.php(类名的首字母大写)(使用load加载libraries时默认执行构造器函数,使用url路由访问控制器时执行构造器函数和默认的index方法。)
paper.php:

<?php
 
class Paper extends CI_Controller
{
  function __construct()
  {
    parent::__construct();
  }
 
  public function pri_body()
  {
 
    $this->load->library('cismarty');
    $this->cismarty->assign("name", 1200);
    $this->cismarty->display('dd.tpl');
 
 
  }
}
?>

 也可以在application/config/autoload.php中配置自动加载资源。

关于如何在CodeIgniter中对Smarty3进行配置问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI