PHP SMARTY 樣板引擎
一、佈景
- 佈景請放在「專案目錄/templates」
 - 使用「bootstrap」
 - 免費樣板:https://startbootstrap.com/
 - 付費樣板:http://wrapbootstrap.com 、https://w3layouts.com/
 
二、轉向
- 套件:jGrowl
 - 官網:https://github.com/stanlemon/jGrowl
 - 將整理好套件放至 「class/」解壓縮
 - head.php #轉向頁面 $_SESSION['redirect']=isset($_SESSION['redirect'])?$_SESSION['redirect']:""; $redirectFile = WEB_PATH."/class/jGrowl/redirect_header.tpl"; $smarty->assign("redirect", $_SESSION['redirect']); $smarty->assign("redirectFile", $redirectFile); $_SESSION['redirect']="";
 - theme.tpl <{if $redirect}> <{include file="file:$redirectFile"}> <{/if}>
 - function.php ############################################################################### # 轉向函數 ############################################################################### function redirect_header($url = "", $time = 3000, $message = '已轉向!!') { $_SESSION['redirect'] = "\$.jGrowl('{$message}', { life:{$time} , position: 'center', speed: 'slow' });"; header("location:{$url}"); exit; }
 - 使用 redirect_header("轉向網址", 停留豪秒, '轉向訊息'); redirect_header("index.php?op=xxx", 3000, '已轉向!!'); exit;
 
三、連結資料庫
- head.php #引入資料庫設定 require_once WEB_PATH.'/sqlConfig.php';
 - sqlConfig.php <?php require_once '../../sqlConfig.php';
 - ../../sqlConfig.php
	
<?php
if($_SERVER["SERVER_NAME"] == "localhost" or $_SERVER["SERVER_NAME"] == "127.0.0.1"){
  #判斷主機為UniServerZ
  #MYSQL
  #資料庫伺服器
  $db_host = "localhost";
 
  #資料庫使用者帳號
  $db_user = "root";
 
  #資料庫使用者密碼
  $db_password = "111111";
 
  #資料庫名稱
  $db_name = "web";
 
}else{
  #MYSQL
  #資料庫伺服器
  $db_host = "localhost";
 
  #資料庫使用者帳號
  $db_user = "user";
 
  #資料庫使用者密碼
  $db_password = "password";
 
  #資料庫名稱
  $db_name = "db";
 
}
 
#PHP 5.2.9以後
$db = new mysqli($db_host, $db_user, $db_password, $db_name);
 
if ($db->connect_error) {
  die('無法連上資料庫 (' . $db->connect_errno . ') '
        . $db->connect_error);
}
 
#設定資料庫語系
$db->set_charset("utf8");
	
 
四、在cpanel 建立資料庫
- 登入cpanel
 - http://cpanel.帳號.ugm.com.tw/
 - 示範:
 - 在uniserverZ 建資料庫
 
五、整理好的專案目錄
- 下載
 - 直接下載至 www/ 解壓縮,再改目錄名稱即可
 - 連結資料庫密碼設定檔 UniServerZ/sqlConfig.php 此檔必須與 專案目錄/sqlConfig.php 對應
	
<?php
require_once '../../sqlConfig.php';
	./ :代表本層目錄
../ :代表上層目錄 
六、將專案目錄上傳,記得也要將UniServerZ/sqlConfig.php 資料庫設定檔上傳至 public_html/sqlConfig.php