該筆記針對 windows 環(huán)境
php-8.2.19-nts-Win32-vs16-x64
)->解壓->配置好ini(不會自行百度)->開啟FFI拓展->配置好環(huán)境運行Enigma Virtual Box
應用
新增->添加文件夾[遞歸] :選擇你的PHP文件夾,這里我選擇的是C:\environment\php-8.2.19-nts
(請根據(jù)你的實際情況選擇)
文件選項:勾選->壓縮文件和勾選->啟動文件虛擬化
執(zhí)行封包(你會拿到一個單文件),這里我的是php-win_boxed.exe
新建文件夾php-webui
(根據(jù)你的實際情況新建)
進入文件夾php-webui
(根據(jù)你的實際情況新建)
執(zhí)行composer(這里我選擇 webui的php桌面拓展)
composer require kingbes/webui
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>phpwebui</title>
<!-- You must add webu.js; otherwise, the interaction cannot be performed -->
<script src="webui.js"></script>
</head>
<body>
<p>hello world for php webui</p>
<button onclick="btn()">btn</button>
<script>
function btn() {
hello('hello').then(function (res) {
console.log(res)
})
}
</script>
</body>
</html>
index.php
<?php
require "./vendor/autoload.php";
use Kingbes\Webui;
use Kingbes\JavaScript;
// 實例
$Webui = new Webui;
// html字符串
$html = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . "index.html");
// 創(chuàng)建一個窗口
$window = $Webui->newWindow();
// 綁定js函數(shù)
$bind = $Webui->bind($window, "hello", function ($event, JavaScript $js) {
// 獲取第一個參數(shù)為字符串
$arg_one = $js->getString($event);
var_dump($arg_one);
// 返回字符串
$js->returnString($event, "nihao");
});
// 顯示窗口
$Webui->show($window, $html);
// 等待
$Webui->wait();
// 釋放所有
$Webui->clean();
php-win_boxed.exe
文件復制到php-webui
文件夾中執(zhí)行指令(測試查看是否成功)
.\php-win_boxed.exe index.php
執(zhí)行應用 Inno Setup
php-win_boxed.exe
文件,我這里選擇是C:\project\php\php-webui\php-win.exe
)->添加文件夾(選擇你新建的 php-webui
,包含你的子文件)->下一步[!注意] 接下來會彈出 是否立即編譯腳本 ,這時候選擇否
然后修改一下代碼
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppExeName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; Parameters:"index.php";
再 編譯
即可
假設你要添加自己的 ico圖標
你就把圖標文件添加到你的php-webui
文件夾中
然后修改以下代碼(我的ico圖標文件夾是favicon.ico
,根據(jù)你的實際情況)
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppExeName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; Parameters:"index.php"; IconFilename:"{app}\favicon.ico"
這個是我打包好的 demo
拿去玩吧
通過網(wǎng)盤分享的文件:setupPHPWebUi.exe
鏈接: https://pan.baidu.com/s/1fC7Sd1Lnt-zio41s5jgJAQ?pwd=w5xc 提取碼: w5xc
本來想用
static-php-cli
的,可以壓縮得更小,且還有micro
來打包,但static-php-cli
搭建起來并不那么順利,所以還是用Enigma Virtual Box
直接給PHP環(huán)境給封包單文件