Home>

Configuration steps for ci and smarty:

1. The first step is to configure ci and download the smarty template. I like this version (smarty-3.1.8).

2. In the second part, extract the downloaded smarty version and rename the libs file inside to smarty and copy this file to the ci \ application \ libraries directory

3. Create a file under the ci \ application \ libraries directory,The file name can be customized,See for example a tp.php document.

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

<?php
if (! 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 ();

Into:

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

okOur configuration has been successful here,Next we start testing

The first step in the test is to set up a controller:

1. Create a file named cesh.php under \ application \ controllers, the file content

<?php
if (! 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 on your smarty installation success!");
   $this->tp->assign ("body", "Welcome to 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 Create a file named ceshi.html in the ci \ application \ views directory. The file content is

<! Doctype html public "-//w3c //dtd xhtml 1.0 transitional //en"
 "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
 <script src="<!-{$Base_url}->js/jquery.min.js" type="text/javascript"></script>
 <link href="<!-{$Base_url}->css/login.css" rel="stylesheet" type="text/css" />
 <title>smarty installation test</title>
</head>
<body>
<h1><{$title}></h1>
<p><{$body}></p>
<ul>
  <{foreach from=$myarray item=v}>
  <li><{$v}></li>
  <{/foreach}>
</ul>
</body>
</html>

Finally enter the address http://localhost/ci/application/index.php/ceshi (the idea ci represents the root directory where you put the files in the ci framework yourself) After running it, you will see the page where you have successfully configured smarty,At this point, the integration and testing of ci and smarty is complete.

php
  • Previous A solution to the problem that the mysql database connection resources cannot be released in the CI framework
  • Next Sixty-five of Manipulating Data in ASPNET 20: Creating New Stored Procedures in TableAdapters