2019年5月26日 星期日

在Scriptcase blank application中應用 smarty

首先在 Tools -> External Libraries 中,建立一個 smarty Library
我這個是設在 Public 中,<Create a new library>
輸入 "smarty",然後,upload 檔案,smarty 中,我們只需要 /lib 目錄裡面的所有檔案,所以,我另外自行壓縮 zip /lib 裡面的所有檔案,然後,再來 upload ,這樣才可以建立一個目錄正確的SC Library使用的部分。

然後,在 SC 程式裡面,使用:
sc_include_library("sys", "smarty", "Smarty.class.php", true, true);
這樣可以引入smarty library
這個動作相當於:require_once('Smarty.class.php');
之後,就可以使用 smarty了
$smarty = new Smarty();

......


例如:我做了一個 blank application,在 execute中,程式如下:

// Start output buffering
ob_start();
// run code in x.php file
// ...
// echo "<html><hrad></head><body>hello world!</body></html>";
sc_include_library("sys", "smarty", "Smarty.class.php", true, true);
// NOTE: Smarty has a capital 'S'
// require_once('Smarty.class.php');
$smarty = new Smarty();
$smarty->assign('name','Ned');
//** un-comment the following line to show the debug console
//$smarty->debugging = true;
// $smarty->display('c:/temp/test.tpl');
echo $smarty->fetch('c:/temp/test.tpl');
// saving captured output to file
file_put_contents('filename.htm', ob_get_contents());
// end buffering and displaying page
ob_end_flush();



沒有留言:

張貼留言

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。