欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP全栈学习笔记19

程序员文章站 2022-03-07 10:11:17
thinkphp框架是一个免费的,开源,快速,简单的面向对象的轻量级PHP开发框架。 了解什么是thinkphp概述,thinkphp项目目录结构,thinkphp的控制器,视图,thinkphp项目构建流程,thinkphp配置,thinkphp的模型,熟悉内置模板引擎。 thinkphp框架的特 ......

PHP全栈学习笔记19

thinkphp框架是一个免费的,开源,快速,简单的面向对象的轻量级php开发框架。

了解什么是thinkphp概述,thinkphp项目目录结构,thinkphp的控制器,视图,thinkphp项目构建流程,thinkphp配置,thinkphp的模型,熟悉内置模板引擎。

thinkphp框架的特点,是一个功能丰富的轻量级的php开发框架,让web应用开发更简单,,更快速。

特性:
类库导入,url模式,编译机制,查询语言,视图模型,分组模块,模板引擎,ajax支持,缓存机制。

thinkphp可以支持windows/unix服务器环境,可运行于包含apache,iis在内的多种web服务。下载thinkphp:

thinkphp的目录结构
自动生成目录
项目目录部署方案
命名规范
项目构建流程

PHP全栈学习笔记19

PHP全栈学习笔记19

自动生成目录

PHP全栈学习笔记19

项目目录部署方案

PHP全栈学习笔记19

PHP全栈学习笔记19

项目构建流程
PHP全栈学习笔记19

thinkphp的配置
配置格式
调试配置

PHP全栈学习笔记19

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 = mysql_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>";
}

结言

好了,欢迎在留言区留言,与大家分享你的经验和心得。

感谢你学习今天的内容,如果你觉得这篇文章对你有帮助的话,也欢迎把它分享给更多的朋友,感谢。

感谢!承蒙关照!您真诚的赞赏是我前进的最大动力!

PHP全栈学习笔记19

PHP全栈学习笔记19