# SmartyMVC **Repository Path**: dreamseeker/SmartyMVC ## Basic Information - **Project Name**: SmartyMVC - **Description**: Index.php控制层:实现单入口MVC - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2013-08-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #SmartyMVC 一、Smarty原理:
1、含有特殊占位符的模版html
2、含有特殊方法通过正则替换模版html的占位符的Smarty.class.php
3、组装替换模版html生成新的php
$smarty->assign("content", $content);
为模版html种的占位符赋值
$smarty->display("demo.html");
替换占位符显示新的php页面
二、本Demo说明:
Index.php控制层:实现单入口MVC
原理:其实就是通过url的地址映射实现的
Index.php页面解析URL地址控制他们做不同的处理
从index.php(入口)构建路由,加载控制器
控制器组织好数据,从smarty输出即可
view就交给smarty了
三、访问方式:
1、web访问方式:
http://localhost/SmartyMVC/index.php/action/PageAction/index?language=en
2、app的HttpClient方法方式:
提供给app的api接口返回json对象:
http://localhost/SmartyMVC/index.php/api/PageAction/index
对于web方式:
Index.php通过解析访问的url调用PageAction的index方法返回含有占位符的模版html,
然后通过smarty的display方法组装成新的php返回
($smarty->setCompileDir(PACKAGE_PATH."/$projectName/templates_c"); 就在这个目录下)
对于app方式:
就不需要Smarty显示view,view的部分就交给app的去组装。
直接通过解析访问的url调用相应的方法。
echo出来json就行了。
#Smarty /Smarty.class.php : 模拟Smarty框架类
主要包括两个方法:
assign($key,$value) : 分配变量方法,用于填充模板的占位符
display($tplfile) : 加载模块方法(通过正则实现)
/tpls/demo.html : 含有特殊占位符的html模板文件
/index.php : 把处理后的结果填充组装,并生成下面的编译(组装)的文件
/temp/con_demo.html.php : 编译(组装)生成的文件