Use the basic configuration of Smarty3 in CodeIgniter

Source: Internet
Author: User
This article mainly introduces the basic configuration of using Smarty3 in CodeIgniter. This article describes how to create a class library and how to call an instance in the controller, so that you can use Smarty completely. For more information, see

This article mainly introduces the basic configuration of using Smarty3 in CodeIgniter. This article describes how to create a class library and how to call an instance in the controller, so that you can use Smarty completely. For more information, see

1. Create a Smarty class library

1. Copy the smarty libs file to libraries (here I will rename it as smarty)
2. Create a Cismarty. php file. (In accordance with the file specifications, the first letter of the file name and the first letter of the class name are capitalized, but the class name/file name does not need to be capitalized when the Controller references loading)

Cismarty. php

<? Phpif (! Defined ('basepath') exit ('no direct script access allowed'); require (APPPATH. 'libraries/smarty/Smarty. class. php '); // CI, the file system uses the relative path relative to index. php path. All URLs use absolute paths. // BASEPATH-The full server path to the "system" folder // APPPATH-The full server path to the "application" folderclass Cismarty extends Smarty {public function _ construct () {parent ::__ construct (); $ this-> caching = false; $ this-> setTemplateDir (APPPATH. 'Views/Smarty/templates'); // you can specify the directory address for all template files. $ This-> setConfigDir (APPPATH. 'Views/Smarty/configs'); // sets the directory for storing the special configuration files of the template, $ this-> setCacheDir (APPPATH. 'Views/Smarty/cache'); // when the cache feature is enabled, all templates of the Smarty cache are placed in the directory specified by this attribute $ this-> setPluginsDir (APPPATH. 'Views/Smarty/INS ins'); // plug-in directory $ this-> setCompileDir (APPPATH. 'Views/Smarty/templates_c '); // sets the directory where all template files compiled by Smarty are stored.}?>

Create a folder named smarty in the corresponding directory. Templates, configs, cache, plugins, templates_c.

Ii. 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 libraries is loaded using load, and the constructor function and default index method are executed when the controller is accessed using url routing .)
Paper. php:

<? Phpclass 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 ') ;}}?>

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

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.