將一個數組輸出到模板中來處理1

1.MSmarty_class.php php

<?php
/*@file:MSmarty_class.php
 * 
 * @title:類,將使用smarty的前三個步聚封起
 * 
 * @author:virhuiai
 *
 * @date:03-21-2013
 * 
 * @modified:03-23-2013
 * 
*/


date_default_timezone_set('PRC');
//require_once('/usr/lib64/php/Smarty/Smarty.class.php');
require_once( 'Smarty/Smarty.class.php' );

class MSmarty extends Smarty{
	function __construct(){
		parent::__construct();

		$this->setTemplateDir('/home/virhuiai/html/test/smarty/templates');
		$this->setCompileDir('/home/virhuiai/html/test/smarty/templates_c');
		$this->setConfigDir('/home/virhuiai/html/test/smarty/configs');
		$this->setCacheDir('/home/virhuiai/html/test/smarty/cache');

		$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
		$this->assign('app_name', 'Guest Book');
	}
}
$smarty = new MSmarty();
//$smarty->right_delimiter='{{';
//$smarty->right_delimiter = '}}';

$right_delimiter='{{';
$right_delimiter = '}}';

//$smarty->assign('name','virhuiai');

//$smarty->display('setup.tpl');

?>

2.try_seciton.php html

<?php 
/*@file:try_seciton.php
 * 
 * @title:類,將使用smarty的前三個步聚封起
 * 
 * @author:virhuiai
 *
 * @date:03-21-2013
 * 
 * @modified:03-23-2013
 * 
*/

include_once './class/MSmarty_class.php';
$people = array('tony','sweety','abc','four');
$smarty->assign('people',$people);

$smarty->display('try_section.tpl');
?>

3.try_seciton.tpl app

{section name=n loop=$people}
     name:{$people[n]}<br/>
{/section}
相關文章
相關標籤/搜索