1. Download the smarty template from the corresponding site;
2. Copy the libs directory in the source code to the libraries directory of the project and rename it to smarty3.0
3. Create a new file ci_smarty.php in the libraries folder of the project directory. The contents are as follows:
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(APPPATH . 'libraries/smarty3.0/Smarty.class.php');
class ci_smarty extends Smarty
{
protected $ci;
public function __construct(){
$this->ci = & get_instance();
$this-> ci->load->config('smarty'); //Load smarty configuration file
//Get related configuration items
$this->template_dir = $this->ci-> ;config->item('template_dir');
$this->complie_dir cache_dir = $this->ci->config->item('cache_dir');
$this->config_dir = $this->ci->config->item('config_dir' );
$this->template_ext = $this->ci->config->item('template_ext');
$this->caching = $this->ci-> ;config->item('caching');
$this->cache_lifetime = $this->ci->config->item('lefttime');
}
}
5. Create a new folder templates_c in the directory where the entry file is located
6. In the project configuration folder, add
to the autoload.php file
$autoload['libraries'] = array('ci_smarty');
7. Create a new file MY_Controller.php in the core folder of the project directory with the following content: // Extend the core control class
8. Test
In controller
In view