In my comany project,due to no time to manage the web structure(php), only leave the pure php files and other scripts in my project.from now on,under the cerntain situation, and with the project on-going and extension,need apply some new style to reorganize the project, The first step is: separate the display and logics. then I select the smarty template as the cutting-point. what's more,I put down the configure.
1.Download Smarty package http://smarty.php.net/
2.Create a directory in web root such as app,then copy the libs folder under the smarty package to app folder.(my web root :C:/work/wwwroot)
3.Modify the php.ini for supporting the smarty template. add this in the php.ini:include_path=".;C:\Work\wwwroot\app\libs"
4.create templates,templates_c,configs,cache folders in the app directory.
5.write down index.php file in the app directory :
<?php
// load Smarty library
require('libs/Smarty.class.php');$smarty = new Smarty;$smarty->template_dir = 'templates';
$smarty->config_dir = 'config';
$smarty->compile_dir = 'templates_c';
$smarty->cache_dir = 'cache';
$smarty->assign('name','fish boy!');
$smarty->display('index.tpl');
?>
6.create a template file(index.tpl) in the templates folder:
<html>
<body>
Hello, {$name}!
</body>
</html>
Basically the directory structure is:
wwwroot
+app
+libs(files from smarty libs folder)
+templates(put the tpl file in this directory)
templates_c
configs
cache
7.run this http://localhost/app
本文介绍了一种通过引入Smarty模板引擎来分离显示层与业务逻辑层的方法,从而实现对现有PHP项目的有效重构。文中详细描述了从下载Smarty包到配置及运行的整个过程,并给出了具体的目录结构和代码示例。
409

被折叠的 条评论
为什么被折叠?



