MVC 设计模式
Model 数据库操作模型
View 视图页面
Controller 控制器
'DB_HOST'=>'127.0.0.1',
'DB_USER'=>'',
'DB_PWD'=>'',
'DB_NAME'=>'',
'DB_PREFIX'=>'',
'TMPL_FILE_DEPR'=>'',
'LOAD_EXT_FILE'=>'function' //配置问件
$this->display(); //引入模板
__PUBLIC__/ 模板内路径
'URL_MODEL'=>1, //换地址
'URL_HTML_SUFFIX' =>'html' //后缀名
U('类名'); //提交地址
I('content','','htmlspecialchars'); //获取POST和GET内容//
C(); 输出
'DB_PREFIX'=>'hd_',
//点语法默认解析数组 这样会比较快
'TMPL_VAR_IDENTIFY' => 'array',
实体化避免注入
mysql
添加数据
M('wish')->data($data)->add() //把data数组中的所有全添加到wish表中
删除数据
M('wish')->where()->delete();
查询
M('wish')->select();
分配值
$this->assign('a',111); $this->a=111;
查询值并分配给wish并引入模板
$this->assig('wish',M('wish')->select())->display('wish');
<foreach name='wish' item='v'>
{$v.username} //输出表中的username
{$v.time|date='m-d H:i',###} //输出表中时间
</foreach>
随机函数
{:mt_rand(1, 5)}
创建表
create table hd_wish
(
id int unsigned not null primary key auto_increment, //名为id 整形 非负 非空 主键 自增
username char(20) not null default '',
content varchar(255) not null default '',
)
//Show 控制器 say 方法
Class ShowAction extends Action{
function say () {
$this ->display();
}
}
//指定错误页面模板路径
'TMPL_EXCEPTION_FILE' => './Public/Tpl/error.html'
halt('页面不存在'); //错误页面
分组步骤
1,先创建大入口:定义项目名称和位置并引入thinkphp
2,打开config.php开启应用分组,并配置数据库
3,建立控制器 IndexAction.class.php
4,在TPL里放入模版 再新建 Public 放入css js
5,
``
Model 数据库操作模型
View 视图页面
Controller 控制器
'DB_HOST'=>'127.0.0.1',
'DB_USER'=>'',
'DB_PWD'=>'',
'DB_NAME'=>'',
'DB_PREFIX'=>'',
'TMPL_FILE_DEPR'=>'',
'LOAD_EXT_FILE'=>'function' //配置问件
$this->display(); //引入模板
__PUBLIC__/ 模板内路径
'URL_MODEL'=>1, //换地址
'URL_HTML_SUFFIX' =>'html' //后缀名
U('类名'); //提交地址
I('content','','htmlspecialchars'); //获取POST和GET内容//
C(); 输出
'DB_PREFIX'=>'hd_',
//点语法默认解析数组 这样会比较快
'TMPL_VAR_IDENTIFY' => 'array',
实体化避免注入
mysql
添加数据
M('wish')->data($data)->add() //把data数组中的所有全添加到wish表中
删除数据
M('wish')->where()->delete();
查询
M('wish')->select();
分配值
$this->assign('a',111); $this->a=111;
查询值并分配给wish并引入模板
$this->assig('wish',M('wish')->select())->display('wish');
<foreach name='wish' item='v'>
{$v.username} //输出表中的username
{$v.time|date='m-d H:i',###} //输出表中时间
</foreach>
随机函数
{:mt_rand(1, 5)}
创建表
create table hd_wish
(
id int unsigned not null primary key auto_increment, //名为id 整形 非负 非空 主键 自增
username char(20) not null default '',
content varchar(255) not null default '',
)
//Show 控制器 say 方法
Class ShowAction extends Action{
function say () {
$this ->display();
}
}
//指定错误页面模板路径
'TMPL_EXCEPTION_FILE' => './Public/Tpl/error.html'
halt('页面不存在'); //错误页面
分组步骤
1,先创建大入口:定义项目名称和位置并引入thinkphp
2,打开config.php开启应用分组,并配置数据库
3,建立控制器 IndexAction.class.php
4,在TPL里放入模版 再新建 Public 放入css js
5,
``