PHP全棧學習筆記19

image.png

thinkphp框架是一個免費的,開源,快速,簡單的面向對象的輕量級PHP開發框架。php

瞭解什麼是thinkphp概述,thinkphp項目目錄結構,thinkphp的控制器,視圖,thinkphp項目構建流程,thinkphp配置,thinkphp的模型,熟悉內置模板引擎。html

thinkphp框架的特色,是一個功能豐富的輕量級的PHP開發框架,讓web應用開發更簡單,,更快速。mysql

特性:
類庫導入,url模式,編譯機制,查詢語言,視圖模型,分組模塊,模板引擎,ajax支持,緩存機制。web

thinkphp能夠支持windows/unix服務器環境,可運行於包含apache,iis在內的多種web服務。下載thinkPHP:ajax

ThinkPHP的目錄結構
自動生成目錄
項目目錄部署方案
命名規範
項目構建流程sql

image.png

image.png

自動生成目錄thinkphp

image.png

項目目錄部署方案數據庫

image.png

image.png

項目構建流程
image.pngapache

ThinkPHP的配置
配置格式
調試配置windows

image.png

ThinkPHP的控制器

控制器
跨模塊調用

一、模型的命名
二、實例化模型
三、屬性訪問
四、鏈接數據庫
五、建立數據
六、連貫操做
七、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>";
}

結言

好了,歡迎在留言區留言,與你們分享你的經驗和心得。

感謝你學習今天的內容,若是你以爲這篇文章對你有幫助的話,也歡迎把它分享給更多的朋友,感謝。

感謝!承蒙關照!您真誠的讚揚是我前進的最大動力!

image

image

相關文章
相關標籤/搜索