標籤

bat (52) 作品 (38) python (21) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

2021年2月21日 星期日

紀明村老師運動檢錄系統程式碼研究心得(三)smarty

整理:
1.只要會用滑鼠點兩下,用shell 在 ubuntu 16.04 x64 桌面版本快速安裝 運動檢錄系統
https://skjhcreator.blogspot.com/2021/03/shell-ubuntu-1604-x64.html
2.紀明村老師運動會競賽檢錄系統更新模組_學生帳號管理模組
https://skjhcreator.blogspot.com/2021/03/blog-post.html
3.二林國小紀明村老師的二林網管 PDO + SQLite 程式寫作工具箱2014.07
https://skjhcreator.blogspot.com/2021/03/pdo-sqlite-201407.html
4.用shell 在CentOS 7 minimal 64位元 安裝 紀明村老師的運動會檢錄系統
https://skjhcreator.blogspot.com/2021/02/shell-centos-7-minimal-64.html
5.紀明村老師的運動檢錄系統程式碼研究心得(一)介接CloudSchool與mysql資料庫
https://skjhcreator.blogspot.com/2021/03/cloudschoolmysql.html
6.紀明村老師運動檢錄系統程式碼研究心得(二)登入login登出logout與使用者認證
https://skjhcreator.blogspot.com/2021/02/loginlogout.html
7.紀明村老師運動檢錄系統程式碼研究心得(三)smarty
https://skjhcreator.blogspot.com/2021/02/smarty.html

第一篇:紀明村老師運動檢錄系統程式碼研究心得(一)介接CloudSchool與mysql資料庫


   為了方便使用,利用shell來建立環境。
檔案名稱:SmartyEnvSetting.sh
檔案內容:
#!/bin/bash
source /etc/os-release
case $ID in
debian|ubuntu|devuan)
    apt-get install -y wget zip unzip
    ;;
centos|fedora|rhel)
    yumdnf="yum"
    if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
        yumdnf="dnf"
    fi
    $yumdnf install -y wget zip unzip
    ;;
*)
    exit 1
    ;;
esac
wget https://github.com/smarty-php/smarty/archive/v3.1.34.zip
unzip v3.1.34.zip
mv smarty-3.1.34/libs /var/www/html/
rm v3.1.34.zip 
rm smarty-3.1.34 -rf
mv libs Smarty3.1.34

   如何使用SmartyEnvSetting.sh?指令如下:
$sudo chmod +x SmartyEnvSetting.sh
$sh SmartyEnvSetting.sh

檔案名稱:SmartySetting.php
檔案內容:
<?php

// 5.可寫入目錄(放置資料庫檔及暫存區用),建議搬至網頁目錄外
define('__SiteData', dirname(__file__).'/Sport_data/');

//  程式目錄,不用修改
define('__SitePtah', dirname(__file__)."/");

//----Smarty class 的位置
$Smarty_class_file=__SitePtah.'Smarty3.1.34/Smarty.class.php';

//----Smarty寫入目錄位置
$Smarty_Compile_DIR=__SiteData.'templates_c/';

//(最後有/,注意:這個目錄是可寫入的)
autoDir(__SiteData);
autoDir($Smarty_Compile_DIR);
//echo "建立 ".__SiteData." OK!<br />";
//echo "建立 ".$Smarty_Compile_DIR." OK!<br />";

//----Smarty物件----------//
require_once $Smarty_class_file;
$smarty = new Smarty();//建立物件
$smarty->error_reporting = E_ALL & ~E_NOTICE; 
$smarty->compile_dir = $Smarty_Compile_DIR;
$smarty->left_delimiter = '{{';//設定樣本檔的左邊標籤
$smarty->right_delimiter = '}}';//設定樣本檔的右邊標籤
//echo "設定--Smarty物件-- OK!<br />";

/*自動建立目錄*/
function autoDir($dir){
//echo $dir.'<br>';
if (file_exists($dir) && is_dir($dir)) return ;
    $rs = @mkdir($dir, 0755); 
if (!$rs) backe($dir."<br>資料存放區不存在或無法建立!");
}

?>

   為了方便使用,利用shell來建立非物件導向的測試檔案。
檔案名稱:SmartyTest.sh
檔案內容:
#!/bin/bash
echo "{{* Smarty *}}" > /var/www/html/Sport_data/templates_c/index.tpl
echo "<br />" >> /var/www/html/Sport_data/templates_c/index.tpl
echo "Hello,{{\$name}}!" >> /var/www/html/Sport_data/templates_c/index.tpl
echo "<?php" > /var/www/html/index.php
echo "include 'SmartySetting.php';" >> /var/www/html/index.php
echo "\$smarty->assign('name','Ned');" >> /var/www/html/index.php
echo "\$smarty->display(\$Smarty_Compile_DIR.'index.tpl');" >> /var/www/html/index.php
echo "?>" >> /var/www/html/index.php

   SmartyTest.sh要建立的檔案index.php與index.tpl,其內容分別如下:
檔案名稱:index.php
檔案位置:/var/www/html/
檔案內容:
<?php
include 'SmartySetting.php';
$smarty->assign('name','Ned');
$smarty->display($Smarty_Compile_DIR.'index.tpl');
?>

檔案名稱:index.tpl
檔案位置:/var/www/html/Sport_data/templates_c/
檔案內容:
{{* Smarty *}}
<br />
Hello,{{$name}}!

   如何使用SmartyTest.sh?指令如下:
$sudo chmod +x SmartyTest.sh
$sh SmartyTest.sh

   接下來,在瀏覽器打上http://伺服器IP/index.php,即可看到

   為了方便使用,利用shell來建立物件導向的測試檔案。
檔案名稱:SmartyObjectTest.sh
檔案內容:
#!/bin/bash
echo "{{* Smarty *}}" > /var/www/html/Sport_data/templates_c/indexObject.tpl
echo "<br />" >> /var/www/html/Sport_data/templates_c/indexObject.tpl
echo "Hello,{{\$this->name}}!" >> /var/www/html/Sport_data/templates_c/indexObject.tpl
echo "<?php" > indexObject.php
echo " include 'SmartySetting.php';" >> indexObject.php
echo " \$name='Test';" >> indexObject.php
echo "//a.建立物件" >> indexObject.php
echo "\$obj= new sport_main(\$smarty,\$name,\$Smarty_Compile_DIR);"
>> indexObject.php
echo " //b.處理程序" >> indexObject.php
echo " \$obj->process();" >> indexObject.php
echo " class sport_main{" >> indexObject.php 
echo " var \$smarty;//smarty物件" >> indexObject.php
echo " var \$name;" >> indexObject.php
echo " var \$Smarty_Compile_DIR;" >> indexObject.php
echo " /* 1.建構函式 */" >> indexObject.php
echo " function __construct(\$smarty,\$name,\$Smarty_Compile_DIR){" >> indexObject.php
echo " \$this->smarty=\$smarty;" >> indexObject.php
echo " \$this->name=\$name;" >> indexObject.php
echo " \$this->Smarty_Compile_DIR=\$Smarty_Compile_DIR;" >> indexObject.php
echo " }" >> indexObject.php
echo "/* 2.初始化一些數值處理函式  */" >> indexObject.php
echo " function init() {" >> indexObject.php
echo " }" >> indexObject.php
echo " /* 3.物件流程函式  */" >> indexObject.php
echo " function process() {" >> indexObject.php
echo " //初始化一些數值" >> indexObject.php
echo " \$this->init();" >> indexObject.php
echo " //擷取資料" >> indexObject.php
echo " \$this->all();" >> indexObject.php
echo " //顯示畫面" >> indexObject.php
echo " \$this->display();" >> indexObject.php
echo " }" >> indexObject.php
echo " /* 4.顯示畫面處理函式*/" >> indexObject.php
echo " function display(){" >> indexObject.php
echo "  \$tpl = \$this->Smarty_Compile_DIR.'/indexObject.tpl';" >> indexObject.php
echo "  \$this->smarty->assign('this',\$this);" >> indexObject.php
echo "  \$this->smarty->display(\$tpl);" >> indexObject.php
echo " }" >> indexObject.php
echo " /* 5.擷取資料給網頁呈現處理函式*/" >> indexObject.php
echo " function all(){" >> indexObject.php
echo " }" >> indexObject.php
echo "}" >> indexObject.php
echo "//end class" >> indexObject.php

   SmartyObjectTest.sh要建立的檔案indexObject.php與indexObject.tpl,其內容分別如下:
檔案名稱:indexObject.php
檔案位置:/var/www/html/
檔案內容:
<?php
include "SmartySetting.php";
$name='Test';
//a.建立物件
$obj= new sport_main($smarty);
//b.處理程序
$obj->process();
class sport_main{
var $smarty;//smarty物件
        var $name;
        var $Smarty_Compile_DIR;
/* 1.建構函式 */
function __construct($smarty,$name,$Smarty_Compile_DIR){
$this->smarty=$smarty;
                $this->name=$name;
                $this->Smarty_Compile_DIR=$Smarty_Compile_DIR;
}
/* 2.初始化一些數值處理函式  */
function init() {
}
/* 3.物件流程函式  */
function process() {
//初始化一些數值
$this->init();
//擷取資料
$this->all();
//顯示畫面
$this->display();
}
/* 4.顯示畫面處理函式*/
function display(){
      $tpl = $this->Smarty_Compile_DIR.'/indexObject.tpl';
      $this->smarty->assign('this',$this);
      $this->smarty->display($tpl);
}
/* 5.擷取資料給網頁呈現處理函式*/
function all(){
}
}
//end class

檔案名稱:indexObject.tpl
檔案位置:/var/www/html/Sport_data/templates_c/
檔案內容:
{{* Smarty *}}
<br />
Hello,{{$this->name}}!

   

資料來源:

沒有留言:

張貼留言

只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...