<?phpif(!defined('BASEPATH'))exit('No direct script access allowed');classDebugextendsMY_Controller{function__construct(){parent::__construct();// Write your own initialize code}functionindex(){$this->load->library('smarty');$this->smarty->assign("title","smarty template");$this->smarty->assign("body","欢迎使用smarty模板引擎");$arr=array(1=>'number 1',2=>'number 2',3=>'number 3');$this->smarty->assign("myarray",$arr);$this->smarty->display('index.html');}}
模板代码:
application/views/templates/index.html
12345678910111213141516
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>smarty模板使用示例</title></head><body><h1>{$title}</h1><p>{$body}</p><ul> {foreach from=$myarray item=v}
<li>{$v}</li> {/foreach}
</ul></body></html>