您的位置:首页 > 编程语言 > PHP开发

ThinkPHP学习-2

2015-11-22 15:38 537 查看

ThinkPHP开发一个项目 ##

# 将ThinkPHP文件夹放到项目目录下
# 创建并编辑index.php文件(前台入口文件)
<?php
define('APP_NAME', 'App');
define('APP_PATH', './App/');
require('./ThinkPHP/ThinkPHP.php');

# 创建并编辑admin.php文件(后台入口文件)
<?php
define('APP_NAME','Admin');
define('APP_PATH','./Admin/');
require('./ThinkPHP/ThinkPHP.php');


ThinkPHP框架目录结构

// common 存放当前项目的公共函数
//Conf 存放当前项目的配置文件
//Lang 存放当前项目的语言包
//Lib 存放当前项目的控制器和模型 MC
//Runtime 存放当前项目的运行时编译文件
//Tpl 存放当前项目的模版文件 V


ThinkPHP框架流程与配置

//流程
//1.加载ThinkPHP.php
//require('./ThinkPHP/ThinkPHP.php');
//2.加载核心文件 ./ThinkPHP/Lib/core
//3.加载项目的文件 分析URL 调用相关控制器
//访问?m=index&a=index(test)
//m module 模块 控制器 a action 方法
$module = isset($_GET['m'])?$_GET['m']:'Index';
$action = isset($_GET['a'])?$_GET['a']:'Index';
$foo = new $module;
$foo -> $action();
class index{
function  __construct(){
echo 'index控制器';
}
function index(){
echo 'index方法';
}
function test(){
echo 'test方法';
}
}


配置

./ThinkPHP/Conf/convention.php

./Conf/config.php 添加值:’name’=>’foo’,

自定义./Conf/userconf.php 需要在config.php中添加’LOAD_EXT_CONFIG’=>’userconfig.php’,

调用方式C(‘name’);

ThinkPHP框架URL模式

什么是URL模式:C(‘URL_MODEL’);

1默认模式pathinfo模式(模块/方法,array)

echo U(‘Index/user’,array(‘id’=>1),’html’,false,’localhost’);//true自动跳转

localhost/index.php/Index/user/id/1.html

0 普通模式 在config.php中添加’URL_MODEL’=>0,

localhost/index.php?m=Index&a=user&id=1

2重写模式 隐藏index.php 需要服务器支持重写模式

localhost/Index/user/id/1.html

3兼容模式

localhost/index.php?s=Index/user/id/1.html

隐藏index.php

apache -httpd.conf 解除‘rewrite.so’之前一行的注释-重启

index.php同级目录下新建.htaccess文件



URL伪静态

’URL_HTML_SUFFIX=>html|html|xml‘

ThinkPHP框架自定义函数库

新建common目录下common.php

例如

<?php
function test(){
echo "hello there!";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  thinkphp app url模式