This article mainly introduced the CI framework integration smarty Step, combined with the case form detailed analysis the CI frame smarty configuration technique and the call method, needs the friend to refer to. We hope to help you.
Specific as follows:
CI combined with smarty configuration steps:
1. The first step is to configure CI and download Smarty template for personal liking (Smarty-3.1.8) this version.
2. The second part of the download to the Smarty version of the extract and then renamed the Libs file in Smarty and then copy the file to the Ci\application\libraries directory
3. Under Ci\application\libraries This directory to create a file, 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. In creating a Ci\application\templates_c folder
6. Open the ci\application\config\autoload.php file
$autoload [' libraries '] = array ();
Change to:
$autoload [' libraries '] = Array (' database ', ' TP ');
OK our configuration here has been successful, then we start to test
The first step in the test is to establish a controller:
1. Under \application\controllers, create a file named Ceshi.php, the contents of the file
<?PHPIF (Defined (' BasePath ')) exit (' No Direct script access allowed '); class Home extends Ci_controller { functio n __construct () { parent::__construct (); $this->load->helper (' url '); $this->tp->assign (' Base_url ', Base_url ()); Define CSS and JS path } function Index () { $this->tp->assign ("title", "Congratulations on Smarty Installation success!") "); $this->tp->assign ("Body", "Welcome to use Smarty template Engine"); $arr = Array (1=> ' Zhang ',2=> ' Xing ',3=> ' Wang '); $this->tp->assign ("MyArray", $arr); $this->tp->display (' ceshi.html ');} }
2. Create a template file in the Ci\application\views directory to create a file named Ceshi.html, 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 address Http://localhost/ci/application/index.php/ceshi (The idea CI represents the root of the file you put in the CI Framework yourself) and you will see the page where you configure Smarty success, Here, the integration and testing of CI and Smarty is complete.
Related recommendations:
Benefit analysis of CI framework using single-case pattern design
Instructions for using PHP cache files extracted from the CI framework
Open debug mode in the CI framework