1,ThinkPHP标准项目目录参考:
├─ThinkPHP.php 框架入口文件
├─Common 框架公共文件
├─Conf 框架配置文件
├─Extend 框架扩展目录
├─Lang 核心语言包目录
├─Lib 核心类库目录
│ ├─Behavior 核心行为类库
│ ├─Core 核心基类库
│ ├─Driver 内置驱动
│ │ ├─Cache 内置缓存驱动
│ │ ├─Db 内置数据库驱动
│ │ ├─TagLib 内置标签驱动
│ │ └─Template 内置模板引擎驱动
│ └─Template 内置模板引擎
└─Tpl 系统模板目录
2,入口文件调用ThinkPHP框架
<?php
require '/ThinkPHP框架所在目录/ThinkPHP.php';
3,开启、关闭调试模式
<?php
define('APP_DEBUG',TRUE); // 开启调试模式
require '/ThinkPHP框架所在目录/ThinkPHP.php';
define('APP_DEBUG',false); // 关闭调试模式
4,控制器调整模板
控制器:
class IndexAction extends Action {
public function index(){
$this->name = 'thinkphp'; // 进行模板变量赋值
$this->display();
}
}
模板:
<html>
<head>
<title>hello {$name}</title>
</head>
<body>
hello, {$name}!
</body>
</html>
5,数据库连接两件配置方式
第一种:
// 添加数据库配置信息
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => '', // 密码
'DB_PORT' => 3306, // 端口
'DB_PREFIX' => 'think_', // 数据库表前缀
第二种:
'DB_DSN' => 'mysql://root@localhost:3306/thinkphp'
6,数据库查询
class IndexAction extends Action {
public function index(){
$Data = M('Data'); // 实例化Data数据模型
$this->data = $Data->select();
$this->display();
}
}
7,模板页面展示
<html>
<head>
<title>Select Data</title>
</head>
<body>
<volist name="data" id="vo">
{$vo.id}--{$vo.data}<br/>
</volist>
</body>
</html>