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