image.PNG
ThinkPHP 框架是一个免费的, 开源, 快速, 简单的面向对象的轻量级 PHP 开发框架.
了解什么是 ThinkPHP 概述, ThinkPHP 项目目录结构, ThinkPHP 的控制器, 视图, ThinkPHP 项目构建流程, ThinkPHP 配置, ThinkPHP 的模型, 熟悉内置模板引擎.
ThinkPHP 框架的特点, 是一个功能丰富的轻量级的 PHP 开发框架, 让 web 应用开发更简单,, 更快速.
特性:
类库导入, url 模式, 编译机制, 查询语言, 视图模型, 分组模块, 模板引擎, Ajax 支持, 缓存机制.
ThinkPHP 可以支持 Windows/unix 服务器环境, 可运行于包含 apache,iis 在内的多种 Web 服务. 下载 ThinkPHP:
ThinkPHP 的目录结构
自动生成目录
项目目录部署方案
命名规范
项目构建流程
image.PNG
image.PNG
自动生成目录
image.PNG
项目目录部署方案
image.PNG
image.PNG
项目构建流程
image.PNG
ThinkPHP 的配置
配置格式
调试配置
image.PNG
ThinkPHP 的控制器
控制器
跨模块调用
1, 模型的命名
2, 实例化模型
3, 属性访问
4, 连接数据库
5, 创建数据
6, 连贯操作
7,CURD 操作
- <?PHP
- $db = array (
- 'server' => 'localhost',
- 'port' => '3306',
- 'username' => 'root',
- 'password' => 'dada',
- 'database' => 'dada'
- );
- $conn = @mysql_connect($db['server'].':'.$db['port'],$db['username'],$db['password']);
- if (! $conn) {
- echo "服务器不能连!" . mysql_error();
- } else {
- // 声明字符集
- mysql_set_charset('utf8', $conn);
- // 选择数据库
- mysql_select_db($db['database'], $conn);
- }
- <?PHP
- if (! isset ( $_SESSION )) {
- session_start ();
- }
- if (! isset ( $_SESSION ['userName'] )) {
- header ( "location:login.php" );
- }
- $userName = $_SESSION ['userName'];
- // 访问数据库, 查询学生表指定学号的学生
- require_once 'dbconfig.php';
- if (! isset ( $_REQUEST ['id'] )) {
- header ( "location:index.php" );
- }
- $id = $_REQUEST ['id'];
- $sql = "select * from student where id = $id";
- // exit($sql);
- $result = mysql_query ( $sql );
- $row = mysql_fetch_array ( $result )?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <HTML>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>
- 学生信息
- </title>
- </head>
- <body>
- <div align='right'>
- 用户名:
- <?=$userName?>
- <a href='loginout.php'>
- 退出登录
- </a>
- </a>
- </div>
- <div align='center'>
- <hr />
- <h1>
- 学生信息
- </h1>
- <form action='editdo.php' method='post'>
- <input type='hidden' name='id' value='<?=$row [' id ']?>'/>
- <table width=300>
- <tr>
- <td align='center'>
- 学号
- </td>
- <td>
- <input type='text' name='studentId' value='<?=$row [' studentId ']?>'
- />
- </td>
- </tr>
- <tr>
- <td align='center'>
- 姓名
- </td>
- <td>
- <input type='text' name='name' value='<?=$row [' name ']?>' />
- </td>
- </tr>
- <tr>
- <td align='center'>
- 班级
- </td>
- <td>
- <input type='text' name='className' value='<?=$row [' className ']?>'
- />
- </td>
- </tr>
- <tr>
- <td align='center'>
- 生日
- </td>
- <td>
- <input type='text' name='birthday' value='<?=$row [' birthday ']?>' />
- </td>
- </tr>
- <tr>
- <td align='center'>
- 性别
- </td>
- <td>
- <input type='radio' name='sex' value='男' <?=$row [ 'sex']=='男' ?
- 'checked': ''?>
- > 男
- </input>
- <input type='radio' name='sex' value='女' <?=$row [ 'sex']=='女' ?
- 'checked': ''?>
- > 女
- </input>
- </td>
- </tr>
- <tr>
- <td align='center'>
- 民族
- </td>
- <td>
- <input type='text' name='nation' value='<?=$row [' nation ']?>' />
- </td>
- </tr>
- <tr>
- <td colspan=2 align='center'>
- <input type='submit' value='确认修改' />
- </td>
- </tr>
- </table>
- </form>
- </div>
- </body>
- </HTML>
- <?PHP
- require_once 'dbconfig.php';
- header ( "content-type:text/html;charset=utf-8" );
- // 取表单数据
- $id = $_REQUEST ['id'];
- $studentId = $_REQUEST ['studentId'];
- $name = $_REQUEST ['name'];
- $className = $_REQUEST ['className'];
- $birthday = $_REQUEST ['birthday'];
- $sex = $_REQUEST ['sex'];
- $nation = $_REQUEST ['nation'];
- // sql 语句中字符串数据类型都要加引号, 数字字段随便
- $sql = "update student set studentId ='$studentId',name ='$name',className ='$className',birthday ='$birthday',sex ='$sex',nation='$nation'where id = $id";
- if (mysql_query ( $sql )) {
- echo "修改成功!!!<br/>";
- echo "<a href='index.php'> 回到主页 </a>";
- } else {
- echo "修改失败!!!<br/>";
- echo "<a href='index.php'> 系统错误 </a>";
- }
- <?PHP
- if (! isset ( $_SESSION )) {
- session_start ();
- }
- if (! isset ( $_SESSION ['userName'] )) {
- header ( "location:login.php" );
- }
- $userName = $_SESSION ['userName'];
- // 访问数据库, 查询学生表
- require_once 'dbconfig.php';
- $sql = "select * from student";
- $result = mysql_query ( $sql );
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <HTML>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>
- 学生信息
- </title>
- </head>
- <body>
- <div align='right'>
- 用户名:
- <?=$userName?>
- <a href='loginout.php'>
- 退出登录
- </a>
- </a>
- </div>
- <hr />
- <h1>
- 学生信息
- </h1>
- <table border=1>
- <tr>
- <th>
- 学号
- </td>
- <th>
- 姓名
- </td>
- <th>
- 班级
- </td>
- <th>
- 生日
- </td>
- <th>
- 性别
- </td>
- <th>
- 民族
- </td>
- <th>
- 操作
- </th>
- </tr>
- <?PHP while ( $row=m ysql_fetch_array ( $result ) ) { echo "<tr>"; echo
- "<td>" . $row [ 'studentId'] . "</td>"; echo "<td>" . $row [ 'name'] .
- "</td>"; echo "<td>" . $row [ 'className'] . "</td>"; echo "<td>" . $row [
- 'birthday'] . "</td>"; echo "<td>" . $row [ 'sex'] . "</td>"; echo "<td>" . $row
- [ 'nation'] . "</td>"; echo "<td>" . "<a href=\"edit.php?id='". $row ['
- id '] ."'\ "> 编辑 </a></td>"; echo "</tr>"; } ?>
- </table>
- </body>
- </HTML>
- <HTML>
- <head>
- <title>Login</title>
- <meta http-equiv="Content-Type" content= "text/html; charset=utf-8">
- </head>
- <body>
- <h1>1606 登录 </h1>
- <form name="form1" method= "post" action= "logindo.php">
- <table width="300" border= "0" align= "center" cellpadding= "2" cellspacing= "2">
- <tr>
- <td width="150"><div align= "right"> 用户名:</div></td>
- <td width="150"><input type= "text" name= username></td>
- </tr>
- <tr>
- <td><div align="right"> 密码:</div></td>
- <td><input type="password" name= "passcode"></td>
- </tr>
- </table>
- <p align="center">
- <input type="submit" name= "Submit" value= "登录">
- <input type="reset" name= "Reset" value= "重置">
- <a href='register.php'> 注册 </a>
- </p>
- </form>
- </body>
- </HTML>
- <?PHP
- header ( "content-type:text/html;charset=utf-8" );
- if (! isset ( $_SESSION )) {
- session_start ();
- }
- if (isset ( $_SESSION ['userName'] )) {
- header ( "location:index.php" );
- } elseif (! isset ( $_REQUEST ['username'] )) {
- header ( "location:login.php" );
- } else {
- $username = $_POST ['username'];
- $passcode = $_POST ['passcode'];
- // 计算摘要
- $password2 = sha1 ( $passcode );
- require_once 'dbconfig.php';
- // 根据用户名和密码去查询帐号表
- $sql = "select * from user where username='$username'and password='$password2'";
- $result = mysql_query ( $sql, $conn );
- if ($row = mysql_fetch_array ( $result )) {
- $_SESSION ['userName'] = $username;
- header ( "location:index.php" );
- } else {
- echo "<script>alert('用户名或密码错误!');</script>";
- echo "用户名或密码错误!<br/>";
- echo "<a href='login.php'> 重新登陆 </a>";
- }
- }
- ?>
- <?PHP
- if(!isset($_SESSION)){
- session_start();
- }
- session_destroy();
- header("location:login.php");
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <HTML>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>
- Insert title here
- </title>
- </head>
- <body>
- <h1 align='center'>
- 欢迎注册
- </h1>
- <hr>
- <form action="registerdo.php" method='post'>
- <label>
- 用户名:
- </label>
- <input type='text' name='username' />
- <label>
- 密码:
- </label>
- <input type='text' name='password' />
- <input type='submit' name='hh' value='提交' />
- </form>
- </body>
- </HTML>
- <?PHP
- require_once 'dbconfig.php';
- header("content-type:text/html;charset=utf-8");
- // 取表单数据
- $username = $_REQUEST['username'];
- $password = $_REQUEST['password'];
- $password2 = sha1($password);
- //sql 语句中字符串数据类型都要加引号, 数字字段随便
- $sql = "INSERT INTO user(id, username, password, status) VALUES (null,'$username','$password2',1)";
- //exit($sql);
- if(mysql_query($sql)){
- echo "注册成功!!!<br/>";
- echo "<a href='login.php'> 去登录 </a>";
- }else{
- echo "注册失败!!!<br/>";
- echo "<a href='register.php'> 重注册 </a>";
- }
结言
好了, 欢迎在留言区留言, 与大家分享你的经验和心得.
感谢你学习今天的内容, 如果你觉得这篇文章对你有帮助的话, 也欢迎把它分享给更多的朋友, 感谢.
感谢! 承蒙关照! 您真诚的赞赏是我前进的最大动力!
image
image
来源: http://www.jianshu.com/p/83b1d26c40f9