MVC:(架构模式
M:model模型
V:view 视图
C:controller 控制器
mvc工作流程:
1.浏览者->调用控制器,对它发出指令
2.控制器->按指令选取一个合适的模型
3.模型->按控制器指令取出相应的数据
4.控制器->按指令选取相应的视图
5.视图->把第三步取到的数据按照用户想要的模样呈现出来
命名:控制器文件:testController.class.php 类名:testController 方法
模型文件:testModel.class.php 类名:testModel 方法
视图文件:testView.class.php 类名:testView 方法
引入文件:include include_once require require_once
作用:
控制器:是调用模型,并调用视图。将模型产生的数据传递给视图,并让相关的视图去显示
模型:是获取数据并处理返回数据
视图:是将取得的数据进行组织,美化等,并最终向用户终端输出
单一入口模式:所有的请求都指向一个脚本文件。 例如:index.php
目录规范:
mvc
libs(类库目录
Controller->testController.class.php (控制器目录
Model->testModel.class.php (模型目录
View->testView.class.php (视图目录
config.php (配置文件
index.php (入口文件目录
模板引擎:
1.基于该引擎开发出的模板要更贴近于标准的html等
2.语法简单易懂
3.良好的缓存机制
4.扩展性良好
5.网络资源多
例如:smarty
引入文件:上一级的文件 "../"
上两级的文件 "../../"
......
配置smarty:
五配置:
$smarty->left_delimiter="{";//左定界符
$smarty->right_delimiter="}";//左定界符
$smarty->template_dir="tpl";//HTML模板地址
$smarty->compile_dir="template_c";//模板编译生成的文件
$smarty->cache_dir="cache";//缓存
//以下两方法略懂就好
$smarty->caching = true;//开启缓存
$smarty->cache_lifeftime = 120;//缓存时间
两方法:
$samrty->assign('方法名','变量值');//往模板里面注入变量
$smarty->display('模板地址');