Home > Backend Development > PHP Tutorial > Using Smarty3 basic configuration in CodeIgniter, codeignitersmarty3_PHP tutorial

Using Smarty3 basic configuration in CodeIgniter, codeignitersmarty3_PHP tutorial

WBOY
Release: 2016-07-13 09:48:18
Original
838 people have browsed it

Use Smarty3 basic configuration in CodeIgniter, codeignitersmarty3

1. Create Smarty class library

1. Copy smarty’s libs file to libraries (I renamed it to smarty here)
2. Create a new Cismarty.php file. (Conforming to file specifications, the first letter of the file name and the first letter of the class name are capitalized, but when the controller reference is loaded, the class name/file name does not need to be capitalized)

Cismarty.php

<&#63;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编译过的所有模板文件的存放目录地址
 
 
  }
 
}
 
&#63;>
Copy after login

Create a new smarty folder in the corresponding directory. templates,configs,cache,plugins,templates_c.

2. Controller file

Create the controller file paper.php (the first letter of the class name is capitalized) (the constructor function is executed by default when using load to load libraries, and the constructor function and the default index method are executed when using url routing to access the controller.)
paper.php:

<&#63;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');
 
 
  }
}
&#63;>

Copy after login

You can also configure automatic loading of resources in application/config/autoload.php.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1024133.htmlTechArticleUse Smarty3 basic configuration in CodeIgniter, codeignitersmarty3 1. Create Smarty class library 1. Copy the smarty libs file to libraries Next (I renamed it to smarty here) 2. Create a new Cismart...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template