Detailed steps for integrating the CI framework with smarty, and detailed steps for integrating the ci framework with smarty
This article describes in detail how to integrate smarty with the CI framework. 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
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Finally, enter the http: // localhost/ci/application/index address. php/ceshi (idea ci indicates that you place the root directory of the file in the ci framework). After running the command, you will see the page on which your smarty configuration is successful, now ci and smarty integration and testing are complete.