tp3.2小结(1)

入口文件:index.php
目录结构:核心,Thinkphp
公共资源,public jq 上传的图片等
应用目录,application 房模块
common:基于模块的公共目录,公共函数
命名:类:首字母大写类名controller.class.php
文件夹同名
命名空间:Home/application Admin/application
控制器命名:帕斯卡命名法
配置文件:config.php 动态配置:C('key',value);
视图:视图下的index文件夹下的xxx.html
控制器:
操作方法的定义:必须是公共的(public),操作方法的命名使用驼峰命名法
前置后置操作:
index();
_before_index();前置操作在index之前执行
_after_index();后置操作之后执行
参数绑定:
普通模式?x=...&y=...
PATHINFO模式:/x/../y/... 分隔符可进行设置(设置属性'URL_PATHINFO_DEPR')
REWRITE模式:是在PATHINFO的基础上添加了重写的,可省去入口文件
伪静态:支持所有的静态后缀,为了满足更好的SEO效果,设置('URL_HTML_SUFFIX'=>'html')
URL大小写敏感可设置
URL生成:U('地址表达式',['参数'],['伪静态后缀'],['显示域名']),
地址表达式:[/模块/控制器/操作#锚点@域名]
参数:?
/a/3/df/4
数组传参['a'=>3,'b'=>4]
AJAX返回:$data = 'ok';
$this->ajaxReturn($data,编码格式,二进制掩码);
跳转和重定向:
$this->success('新增成功', 'User/list');
$this->error('新增失败');
参数 提示信息;跳转地址;跳转时间
redirect();直接跳转
获取变量:I();
I('变量类型.变量名/修饰符',['默认值'],['过滤方法'],['额外数据源'])
变量类型:get,post,ajax......
I('get.name/d or s b a f','htmlspecialchars')
请求类型:is_get;is_post;is_put;....(此处全部大写)
demo: if (IS_POST){
$User = M('User');
$User->create();
$User->save();
$this->success('保存完成');
}else{
$this->error('非法请求');
}
连接数据库:
配置文件里进行配置;
在模型里进行设置:
protected $connection = array(
'db_type' => 'mysql',
'db_user' => 'root',
'db_pwd' => '1234',
'db_host' => 'localhost',
'db_port' => '3306',
'db_name' => 'thinkphp',
'db_charset' => 'utf8',
);
连贯操作:
where('type=1 AND status=1')->select();
where(['type'=>1],['status'=>2])->select();
field('id,title,content')->select();
$Model->where('status=1')->order('id desc,status')->limit(5)->select();
$Article->limit('10,25')->select();
$Article->limit('0,10')->select();
$this->field('username,max(score)')->group('user_id')->select();
$this->field('username,max(score)')->group('user_id')->having('count(test_time)>3')->select();
$Model
->join('__WORK__ ON __ARTIST__.id = __WORK__.artist_id')
->join('__CARD__ ON __ARTIST__.card_id = __CARD__.id')
->select();

 sql一对一

sql一对多

C()config
m()model
u()url
I()获取变量

猜你喜欢

转载自www.cnblogs.com/shangXR/p/9838755.html