您好,欢迎访问一九零五行业门户网

Smarty模板引擎的使用

一、为什么使用smarty?
php代码与html代码混合在一起,很混乱。smarty将表现层(前端)和逻辑层(后端)分开。利用smarty缓存技术,有效提高访问速度。二、smarty的原理&使用
原理可以用一张图来表示
使用方法
1:在index.php中引入smarty的入口文件:smarty.class.php
2:实例化一个smarty类;
3:通过对象配置smarty的编译目录、模板目录,缓存目录等等。
4:可将配置文件专门放在一个文件里。
代码
index.php文件
assign(name,$name); //引入模板$smarty->display(index.tpl); ?>
smarty.inc.php文件
php /** * smarty 配置文件 *///创建一个实际路径,加快速度define(root_path,dirname(__file__)); //引入smarty入口文件require(root_path./smarty.class.php); //实例化一个smarty$smarty=new smarty(); //配置文件//模板目录$smarty->template_dir=root_path./templates; //缓存目录$smarty->cache_dir=root_path./cache; //配置目录$smarty->config_dir=root_path./configs; //配置编译目录$smarty->compile_dir=root_path./compile; ?>
').addclass('pre-numbering').hide(); $(this).addclass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadein(1700); }); }); 以上就介绍了smarty模板引擎的使用,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息