PHP框架_ThinkPHP基础
目录
1.ThinkPHP项目结构
2.ThinkPHP运行流程
3.ThinkPHP配置文件
4.ThinkPHP四种URL模式
5.ThinkPHP用户自定义函数
6.ThinkPHP模板展示及变量赋值
7.ThinkPHP模板引擎--循环
8.ThinkPHP模板引擎--判断
1.ThinkPHP项目结构
|ThinkPHP
|--App 用户文件
|--Common 存放当前项目的公告函数
|--Conf 项目的配置文件
|--Lang 项目的语言包
|--Lib 项目的控制器和模型
|--Runtime 项目运行时的文件
|--Tpl 项目的模板文件
|--ThinkPHP ThinkPHP核心文件
|--index.php 入口文件
//自动创建文件结构 #Common 存放当前项目的公告函数 #Conf 项目的配置文件 #Lang 项目的语言包 #Lib 项目的控制器和模型 #Runtime 项目运行时的文件 #Tpl 项目的模板文件 define("APP_NAME","App"); define("APP_PATH","./App/"); require "ThinkPHP/ThinkPHP.php";
2.ThinkPHP运行流程
/* 1.加载ThinkPHP.php require "ThinkPHP/ThinkPHP.php"; 2.加载核心文件 ./ThinkPHP/Lib/Core 3.加载项目的文件 分析url 调用相关控制器 m: module 模块 控制器 a: action 方法 aciotn=页面 */
3.ThinkPHP配置文件
/* 1.首先加载:ThinkPHP/ conf/convention.php 2.再加载用户配置文件App/Conf/config.php 3.修改配置文件需要设置"APP_DEBUG"为"true",每次刷新网页都加载配置 */ define("APP_DEBUG","true");
4.ThinkPHP四种URL模式
/* 模式 1 :默认模式 pathinfo http://localhost/ThinkPHP/index.php/Index/user/id/1.html 模式 0 :普通模式 http://localhost/ThinkPHP/index.php?m=Index&a=user&id=1 模式 2 :重写模式 http://localhost/ThinkPHP/Index/user/id/1.html 模式 3 :兼容模式 http://localhost/ThinkPHP/index.php?s=/Index/user/id/1.html */
5.ThinkPHP用户自定义函数
定义在App/Common下,规定命名为common.php
6.ThinkPHP模板展示及变量赋值
//变量赋值 $name="Ryan"; $this->name = $name; //变量赋值 $this->assign("age","11")->assign("sex","man"); //显示html模板 $this->display("index");
7.ThinkPHP模板引擎--循环
//name:要循环的数组 //id:数组中的项 //offset:数组起始位置 //length:要截取的数组长度 //empty:为空时默认输出 <volist name="demo" id="data" offset="2" length="2" empty="没有数据"> {$data.name} </volist> <foreach name="demo" item="data"> </foreach> //eq = neq != gt > egt>= it < elt<= heq === nheq !== //end默认为小于10 comparison="elt"设置为小于等于 <for start="1" end="10" comparison="elt" name="k"> {$k} </for>
8.ThinkPHP模板引擎--判断
<!--if判断--> <if condition="$num gt 10"> 数字大于10 <elseif condition="$num lt 10"/> 数字小于10 <else/> 数字等于10 </if> <!--switch判断--> <switch name="num"> <case value="11">数字大于10</case> <case value="9" >数字小于10</case> <default/>数字等于10 </switch>
<!-- <比较标签 name="变量名" value="比较的值"></比较标签> --> <eq name="num" value="10">num=10</eq> <neq name="num" value="10">num!=10</neq> <eq name="num" value="10">num=10<else/>num!=10</eq> <compare name="num" value="10" type="eq">num=10<else/>num!=10</compare>
<!--区间判断 in notin between notbetween--> <in name="num" value="10,11,12">在这个区间</in> <in name="num" value="10,11,12">在这个区间<else/>不在这个区间</in> <notin name="num" value="1,2,3">不在这个区间</notin> <between name="num" value="1,20">num在1到20之间</between>