项目里添加smarty功能步骤

来源:互联网 发布:网络最火尴舞视频 编辑:程序博客网 时间:2024/06/12 10:35

项目里添加smarty功能步骤


1把smarty的libs文件夹拷到项目路径下,并写子类

<?phpdefined('acc')||exit('acc denied');//加载父类文件require(ROOT.'lib/smarty/Smarty.class.php');class mysmarty extends Smarty{public function __construct(){parent::__construct();// 设置模板,编译后文件,缓存 地址$this->setTemplateDir(ROOT.'view/front');$this->setCompileDir(ROOT.'data/comp');$this->setCacheDir(ROOT.'data/cache');$this->caching=true;}}?>
2 init文件中引入

require(ROOT.'include/mysmarty.php');

$smarty=new mysmarty();


smarty中自动加载和自己写的自动加载冲突的话

就自己写的__autoload改个名,再在spl_autoload_register中引入函数名,就不会和smarty里的冲突了

function __autoloadshop($class){if (strtolower(substr($class, -5))=='model') {require(ROOT.'model/'.$class.'.class.php');}elseif (strtolower(substr($class, -4))=='tool') {require(ROOT.'tool/'.$class.'.class.php');}else{require(ROOT.'include/'.$class.'.class.php');}}spl_autoload_register('__autoloadshop');


3在控制器把数据assgin和display

// include('./view/front/index.html');/*$smarty->assgin('new',$new);$smarty->assgin('woman',$woman);$smarty->assgin('man',$man);*/// display不需要地址,只需文件名$smarty->display('index.html');

4到对应的html里换delimiter



0 0