CI framework integration smarty step Description _ PHP

Source: Internet
Author: User
This article mainly introduces the integration of smarty in the CI framework, and analyzes in detail the configuration skills and calling methods of Smarty in the CI framework based on the instance form, for more information about how to integrate smarty with the CI framework, see the following section. We will share this with you for your reference. The details are as follows:

Ci configuration steps in combination with smarty:

1. the first step is to configure ci and download the smarty template (Smarty-3.1.8.

2. extract the downloaded version of smarty and rename the libs file in it as smarty. then copy the file to the ci \ application \ libraries Directory.

3. create a file under the ci \ application \ libraries Directory. the file name can be customized. for example, see A tp. php document.

4. open tp. php with the compiler and write the following code:

<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');require_once('smarty/smarty.class.php');class Tp extends Smarty{ function tp(){  parent::Smarty();  $this->template_dir = APPPATH.'views';  $this->compile_dir = APPPATH.'templates_c/';  $this->left_delimiter = '<{';  $this->right_delimiter = '}>'; }}

5. create a ci \ application \ templates_c folder

6. open the ci \ application \ config \ autoload. php file

$autoload['libraries'] = array();

Changed:

$autoload['libraries'] = array('database','tp');

OK, our configuration is successful here. Next, let's start testing.

The first step of the test is to create a controller:

1. create a file named ceshi. php under \ application \ controllers. the file content

<? Phpif (! Defined ('basepath') exit ('no direct script access allowed'); class Home extends CI_Controller {function _ construct () {parent :__ construct (); $ this-> load-> helper ('URL'); $ this-> tp-> assign ('base _ url', base_url ()); // define the path of css and js} function index () {$ this-> tp-> assign ("title", "Congratulations, smarty is installed successfully! "); $ This-> tp-> assign (" body "," Welcome to the smarty template engine "); $ arr = array (1 => 'zhang ', 2 => 'X', 3 => 'wang'); $ this-> tp-> assign ("myarray", $ arr ); $ this-> tp-> display('ceshi.html ');}}

2. create a template file and set the file name to ceshi.html in the ci \ application \ viewsdirectory. the file content is

  
  

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.