TP目录结构
框架公共入口文件ThinkPHP.php不能直接执行,改文件只能在项目入口文件中调用才能正常运行。
新建index.php写入代码:
require 'tp/ThinkPHP.php';
TP自动生成项目目录,目录结构如下:
配置文件:Conf/config.php
控制器命名规范:模块名+Action.class.php
URL请求:
普通模式:http://localhost/app/?m=module&a=action&var=value
PATHINFO模式:http://localhost/app/index.php/module/action/var/value/
REWRITE模式:http://localhost/app/module/action/var/value/
视图定义规范:Tpl/模块名/操作名.html
DSN格式:数据库类型://用户名:密码@数据库地址:数据库端口/数据库名
查询语句
对象方式
表达式查询
连贯操作
├─ThinkPHP.php 框架入口文件
├─Common 框架公共文件
├─Conf 框架配置文件
├─Extend 框架扩展目录
├─Lang 核心语言包目录
├─Lib 核心类库目录
│ ├─Behavior 核心行为类库
│ ├─Core 核心基类库
│ ├─Driver 内置驱动
│ │ ├─Cache 内置缓存驱动
│ │ ├─Db 内置数据库驱动
│ │ ├─TagLib 内置标签驱动
│ │ └─Template 内置模板引擎驱动
│ └─Template 内置模板引擎
└─Tpl 系统模板目录框架公共入口文件ThinkPHP.php不能直接执行,改文件只能在项目入口文件中调用才能正常运行。
新建index.php写入代码:
require 'tp/ThinkPHP.php';
TP自动生成项目目录,目录结构如下:
├─index.php 项目入口文件
├─Common 项目公共文件目录
├─Conf 项目配置目录
├─Lang 项目语言目录
├─Lib 项目类库目录
│ ├─Action Action类库目录
│ ├─Behavior 行为类库目录
│ ├─Model 模型类库目录
│ └─Widget Widget类库目录
├─Runtime 项目运行时目录
│ ├─Cache 模板缓存目录
│ ├─Data 数据缓存目录
│ ├─Logs 日志文件目录
│ └─Temp 临时缓存目录
└─Tpl 项目模板目录开启调试模式:define(‘APP_DEBUG’,TRUE);配置文件:Conf/config.php
控制器命名规范:模块名+Action.class.php
URL请求:
普通模式:http://localhost/app/?m=module&a=action&var=value
PATHINFO模式:http://localhost/app/index.php/module/action/var/value/
REWRITE模式:http://localhost/app/module/action/var/value/
视图定义规范:Tpl/模块名/操作名.html
DSN格式:数据库类型://用户名:密码@数据库地址:数据库端口/数据库名
查询语句
$User = (‘User’);
$User->where(‘type=1 AND status=1’)->select();
$User->where(array(‘name’=>1,’status’=>1))->select();
$User->where(array(‘name’=>1,’_logic’=>’OR’,’status’=>1))->select();对象方式
$condition = new strClass();
$condition->name = ‘SNK’;
$condition->status = 1;
$User->where($condition)->select();表达式查询
$map[‘id’] = array(‘eq’,100);
$map[‘id’] = array(‘neq’,100);
$map[‘id’] = array(‘gt’,100);
$map[‘id’] = array(‘egt’,100);
$map[‘id’] = array(‘lt’,100);
$map[‘id’] = array(‘elt’,100);
$map[‘id’] = array(‘like’,’tp%’);
$map[‘a’] = array(‘like‘,array(‘%tp%’,’$tps’),’OR’);
$map[‘id’] = array(‘between’,’1,8’);
$map[‘id’] = array(‘not in’,’1,2,3’);
$map[‘id’] = array(‘exp’,’IN(1,3,8)’);连贯操作
$User->where(‘status=1’)->order(‘create_time’)->limit(10)->select();
//Where($where)查询或更新条件的定义
//Table($table)定义要操作的数据表名称,可以用别名和跨库操作
$Model->Table(‘db_name.think_user user’)->where(‘status>1’)->select();
$Model->Table(array(‘think_user’=>’user’,’think_group’=>’group’))->where(‘status>1’)->select();
//Data($data)用于增加或保存数据之前的数据对象赋值
$Model->data($data)->add();
$Model->data($data)->where(‘id=3’)->save();
//Field($filed,$except=false)定义要查询的字段
$Model->field(‘id,nickname as name’)->select();
$Model->field(array(‘id’,’nickname’=>’name’))->select();
//Order($order)对操作结果排序
Order(‘id desc’);
Order(‘status desc,id asc’);
Order(array(‘status’=>’desc’,’id’));
//Limit($limit)定义要查询的结果限制
Limit(1,10);
//Page($page[,$pagesize])定义要查询的数据分页($pagesize每页显示记录数)
Page(‘2,10’);
Group(‘user_id’);
Having(‘user_id>0’);
$Model->join(‘work ON artist.id = work.artist_id’)->join(‘card ON artist.card_id = card.id’)->selct();
$Model->join(‘RIGHT JOIN work ON artist.id = work.id’);
$Model->field(‘name’)->table(‘think_user_0’)->union(‘SELECT name FROM think_user_1’)->union(‘SELECT name FROM think_user_2’)->select();
$Model->Distinct(true)->field(‘name’)->selct();
$id=$_GET[‘id’];
$name=$_POST[‘name’];
$value=$_SESSION[‘var’];
$name=$_COOKIE[‘name’];
$file=$_SERVER[‘PHP_SELF’];
//----------------------------------------------------------
$id=$this->_get(‘’id);
$name=$this->_post(‘name’);
$value=$this->_session(‘var’);
$name=$this->_cookie(‘name’);
$file=$this->_server(‘PHP_SELF’);
获取URL参数:$this->_param(0);

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



