欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

CodeIgniter中使用Smarty3基本配置

时间:2021-04-16 08:26:32|栏目:PHP代码|点击:

一、创建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中配置自动加载资源。

上一篇:PHP学习正则表达式 课件第1/2页

栏    目:PHP代码

下一篇:php实现zip文件解压操作

本文标题:CodeIgniter中使用Smarty3基本配置

本文地址:http://www.codeinn.net/misctech/102608.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有