```
~~~
本節課大綱:
一、多應用配置技巧
二、使用分組
三、頁面跳轉
$this->success('查詢成功',U('User/test'));
$this->redirect('User/test','',5,'頁面正在跳');
四、Ajax技巧
前后臺公用公共配置文件:
$ pwd
/cygdrive/c/wamp/www/thinkphp5/Admin/Conf
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5/Admin/Conf
$ ls
config.php
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5/Admin/Conf
$ cat config.php
<?php
$arr=include './config.php';
$arr2=array(
);
return array_merge($arr,$arr2);
?>
// 當前目錄下的config.php,這個當前是指主入口的路徑:
$arr=include './config.php';
公用配置文件:
$ pwd
/cygdrive/c/wamp/www/thinkphp5
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ ls -ltr config.php
-rwxrwx---+ 1 Administrators None 393 五月 9 13:14 config.php
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ cat config.php
<?php
return array(
//'配置項'=>'配置值'
'TMPL_L_DELIM'=>'<{', //配置左定界符
'TMPL_R_DELIM'=>'}>', //配置右定界符
'DB_PREFIX'=>'', //設置表前綴
'DB_DSN'=>'mysql://root:1234567@192.168.32.79:3306/devops', //DSN方式配置數據庫信息
'SHOW_PAGE_TRACE'=>true,//開啟頁面Trace
/* 'URL_ROUTER_ON'=>true,
'URL_ROUTE_RULES'=>array(
':id/:num'=>'Index/index',
), */
);
?>
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
thinkphp 分組機制:
<?php
//1.確定應用名稱 Home
define('APP_NAME','App');
//2. 確定應用路徑 ./Home 當前目錄 index.php的當前目錄 前臺文件夾
define('APP_PATH','./App/');
//開啟調試模式
define('APP_DEBUG',true);
//4.引入核心文件 include 引入的東西錯誤 代碼繼續運行 require 出錯立即結束
require './ThinkPHP/ThinkPHP.php';
?>
'APP_GROUP_LIST' => 'Home,Admin', //項目分組設定
'DEFAULT_GROUP' => 'Home', //默認分組
在同一個應用下,再分不同的應用:
$ pwd
/cygdrive/c/wamp/www/thinkphp6/App/Lib/Action
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp6/App/Lib/Action
$ ls
Admin Home IndexAction.class.php
整個應用叫app應用:
<?php
//1.確定應用名稱 Home
define('APP_NAME','App');
//2. 確定應用路徑 ./Home 當前目錄 index.php的當前目錄 前臺文件夾
define('APP_PATH','./App/');
//開啟調試模式
define('APP_DEBUG',true);
//4.引入核心文件 include 引入的東西錯誤 代碼繼續運行 require 出錯立即結束
require './ThinkPHP/ThinkPHP.php';
?>
推薦使用分應用的方式,而不是分組
分應用情況下的訪問方式,多應用配置技巧:
$ pwd
/cygdrive/c/wamp/www/thinkphp5
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ ls
Admin admin.php config.php Home index.php ThinkPHP
Home前臺應用文件夾:
Admin后臺應用文件夾:
http://localhost/thinkphp5/admin.php
http://localhost/thinkphp5/index.php
//頁面跳轉:
<?php
// 本類由系統自動生成,僅供測試用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配給前臺,表示為list
$this->assign('list','$arr');
$this->display();
}
}
前端頁面:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<table border='1' width='500'>
<foreach name='list' item='vo'>
<tr><td><{$vo.username}></td></tr>
</foreach>
</table>
</body>
</html>
//超鏈接:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<table border='1' width='500'>
<foreach name='list' item='vo'>
<tr><td><a href="__URL__/info?id=<{$vo.id}>"><{$vo.username}></a></td></tr>
</foreach>
</table>
</body>
</html>
<?php
// 本類由系統自動生成,僅供測試用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配給前臺,表示為list
$this->assign('list',$arr);
$this->display();
}
public function info(){
$id=$_GET['id'];
$user=M('user');
$arr=$user->find($id);
dump($arr);
if ($arr){
$this->success('index');
}
else {
//失敗后自動跳轉到上一頁
$this->error('查詢失敗');
}
$this->assign('list',$arr);
$this->display();
}
}
//redirect 跳轉:
<?php
// 本類由系統自動生成,僅供測試用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配給前臺,表示為list
$this->assign('list',$arr);
$this->display();
}
public function info(){
$id=$_GET['id'];
$user=M('user');
$arr=$user->find(100);
dump($arr);
if ($arr){
$this->success('index');
}
else {
//失敗后自動跳轉到上一頁
$this->redirect('User/index');
}
$this->assign('list',$arr);
$this->display();
}
}
跳轉到:
http://localhost/thinkphp5/index.php/User/index
User/index 頁面
Ajax 技巧:
在框架里面,腳本都是被方法所取代
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="__PUBLIC__/Js/jquery.js"></script>
<script>
$(function(){
$('button').bind('click',function(){
$.get('__URL__/getAjax',function(jdata){
<!--alert (JSON.stringify(data));-->
if (jdata.status==1){
alert(jdata.data);
}
});
});
});
</script>
</head>
<body>
<div style='height:50px;background:yellow' id='did'></div>
<button>點擊</button>
<script>
document.write(new Date());
</script>
</body>
</html>
<?php
class IndexAction extends Action {
public function index(){
$this->display();
}
public function getAjax(){
//echo 'aaaaaaa';
$this->ajaxReturn('這里是數據','信息1',1);
}
}
~~~
```
- thinkphp6執行流程(一)
- php中use關鍵字用法詳解
- Thinkphp6使用騰訊云發送短信步驟
- 路由配置
- Thinkphp6,static靜態資源訪問路徑問題
- ThinkPHP6.0+ 使用Redis 原始用法
- smarty在thinkphp6.0中的最佳實踐
- Thinkphp6.0 搜索器使用方法
- 從已有安裝包(vendor)恢復 composer.json
- tp6with的用法,表間關聯查詢
- thinkphp6.x多對多如何添加中間表限制條件
- thinkphp6 安裝JWT
- 緩存類型
- 請求信息和HTTP頭信息
- 模型事件用法
- 助手函數匯總
- tp6集成Alipay 手機和電腦端支付的方法
- thinkphp6使用jwt
- 6.0session cookie cache
- tp6筆記
- TP6(thinkphp6)隊列與延時隊列
- thinkphp6 command(自定義指令)
- command(自定義指令)
- 本地文件上傳
- 緩存
- 響應
- 公共函數配置
- 七牛云+文件上傳
- thinkphp6:訪問多個redis數據源(thinkphp6.0.5 / php 7.4.9)
- 富文本編輯器wangEditor3
- IP黑名單
- 增刪改查 +文件上傳
- workerman 定時器操作控制器的方法
- 上傳文件到阿里云oss
- 短信或者郵箱驗證碼防刷代碼
- thinkphp6:訪問redis6(thinkphp 6.0.9/php 8.0.14)
- 實現關聯多個id以逗號分開查詢數據
- thinkphp6實現郵箱注冊功能的細節和代碼(點擊鏈接激活方式)
- 用mpdf生成pdf文件(php 8.1.1 / thinkphp v6.0.10LTS )
- 生成帶logo的二維碼(php 8.1.1 / thinkphp v6.0.10LTS )
- mysql數據庫使用事務(php 8.1.1 / thinkphp v6.0.10LTS)
- 一,創建過濾IP的中間件
- 源碼解析請求流程
- 驗證碼生成
- 權限管理
- 自定義異常類
- 事件監聽event-listene
- 安裝與使用think-addons
- 事件與多應用
- Workerman 基本使用
- 查詢用戶列表按拼音字母排序
- 擴展包合集
- 查詢用戶數據,但是可以通過輸入用戶昵稱來搜索用戶同時還要統計用戶的文章和粉絲數
- 根據圖片的minetype類型獲取文件真實拓展名思路
- 到處excel
- 用imagemagick庫生成縮略圖
- 生成zip壓縮包并下載
- API 多版本控制
- 用redis+lua做限流(php 8.1.1 / thinkphp v6.0.10LTS )
- 【thinkphp6源碼分析三】 APP類之父, 容器Container類
- thinkphp6表單重復提交解決辦法
- 小程序授權
- 最簡單的thinkphp6導出Excel
- 根據訪問設備不同訪問不同模塊
- 服務系統
- 前置/后置中間件
- 給接口api做簽名驗證(php 8.1.1 / thinkphp v6.0.10LTS )
- 6實現郵箱注冊功能的細節和代碼(點擊鏈接激活方式)
- 使用前后端分離的驗證碼(thinkphp 6.0.9/php 8.0.14/vue 3.2.26)
- 前后端分離:用jwt+middleware做用戶登錄驗證(php 8.1.1 / thinkphp v6.0.10LTS )
- vue前后端分離多圖上傳
- thinkphp 分組、頁面跳轉與ajax
- thinkphp6 常用方法文檔
- 手冊里沒有的一些用法
- Swagger 3 API 注釋
- PHP 秒級定時任務
- thinkphp6集成gatewayWorker(workerman)實現實時監聽
- thinkphp6按月新增數據表
- 使用redis 實現消息隊列
- api接口 統一結果返回處理類
- 使用swoole+thinkphp6.0+redis 結合開發的登錄模塊
- 給接口api做簽名驗證
- ThinkPHP6.0 + UniApp 實現小程序的 微信登錄
- ThinkPHP6.0 + Vue + ElementUI + axios 的環境安裝到實現 CURD 操作!
- 異常$e
- 參數請求驗證自定義和異常錯誤自定義