一、TP框架的下载和安装
Tp框架下载网址:http://www.thinkphp.cn/
在wamp的www目录下创建一个目录tpshop目录
1. 将下载好的包压缩后将文件包里的所有文件复制到创建项目的根目录(tpshop)中
|Application
|Public
|ThinkPHP
|.htaccess
|composer.json
|index.php
|README.md
2.index.php就是我们要创建的项目的入口文件
//定义项目名称
define(‘APP_NAME’,’App’);
// 定义项目路径
define(‘APP_PATH’,’./Application/’);
3.访问localhost/tpshop/index.php/App/Index/index此时项目就创建好了
Common 项目公共文件目录 一般放置项目的公共函数
Conf 项目的配置目录 放置所有的配置文件
Lib 项目类库目录 包括Action和Model子目录
Tpl 项目的模板目录 支持模板主题
Extend 框架的扩展目录
4.错误日志位置
Runtime/logs/ cache 编译目录
5.Tp访问地址参数
http://localhost/tpshop/index.php/APP/Index/index/10;
6.模板标签配置和数据库配置!模板标签默认是{};也可以进行更改、在配置文件中
return array(
/定界符*/
‘TMP_L_DELIM’ => ‘<{',
‘TMP_R_DELIM’ =>’}>’,
//
);
7.__ROOT__输出的是项目根目录; /tpshop
__APP__当前项目的路径 /tpshop/index.php
__URL__当前项目的模块 /tpshop/index.php/Index
__ACTION__当前项目的操做的URL地址 /tpshop/index.php/Index/index
__PUBLIC__ 会被替换成当前项目的 Public目录
__SELF__ 会替换成当前的URL
注意:tp中静态资源一定要网站的绝对路径
8.Thinkphp支持四种URL模式
① 普通模式
http://localhost/test/index.php?m=Index&a=index&id=10
获取模块和方法名称
MODULE_NAME
ACTION_NAME
②pathinfo模式
http://laocalhost/test/index.php/Index/index/id/10;
③rewrite模式
http://localhost/test/Index/index/id/10;
使用rewrite模式一定要修改apache配置文件
1)开启 LoadModule rewrite_module modules/mod_write.so
2)修改网站根目录支持rewrite地址重写
Options Indexs FolloewSymLinks
#一定要把multivews去掉
AllowOverride All
Order allow,deny
Allow from all
3)重启apache
4) 把.htaccess放到入口文件的目录下:
Options +FollowSymlinks
RewriteEngine On
④兼容模式
http://localhost/test/?s=/Index.index/id/10;
9.配置中默认访问模块和方法
‘DEFULT_MODULE’ => ‘Index’ //默认模块名称
‘DEFAULT_ACTION’ => ‘index’ //默认操作方法
10 读取配置
C(‘参数名称’); //获取config中的设置的参数值
11.显示模板 $this->display(); 分配变量到模板:$this->assign(‘data’,$data);
本模块地址跳转$this->success(‘ok’,’index’);
跨模块跳转:$this->success(‘添加成功’,U(‘Login/index’));
重定向 $this->redirect();
12 支持多函数过滤
“DEFAULT_FILIER” => “trim,htmlspecialchars,strip_tags”;
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/229992.html原文链接:https://javaforall.net
