php培训12.22
生活随笔
收集整理的這篇文章主要介紹了
php培训12.22
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這兩天學到了smarty的分離頁面的過程。感覺到了smarty的便捷性,減少了不少的代碼。不過其中的邏輯關系要是復雜點了容易把我們繞進去。從這個角度看,smarty 的便捷性還待提高。可能是我現在還不熟練吧!下面就把這兩天的過程和一些代碼寫下來看看吧。 主題:圍繞cms登錄過程做的一些事情 一:登錄界面: 先是建立個login.php文件;在里面寫出html 表單,然后在表單里講用戶名,密碼,驗證碼。關鍵在驗證碼里包含個Vcode.php和Vcode.class.php. <?php /* *名稱:vcode.php *作用:生成驗證碼 *說明: *作者:KuaiYigang@xingmo.com *時間:2004-11-01 *更新:2006-6-21 */ require_once 'init.php'; $Vcode = new Vcode; header("Content-type:p_w_picpath/png"); $p_w_picpath = $Vcode->createImage();//生成隨機數(放在類的Code屬性中),根據隨機數創建圖像 $_SESSION['Hongye'] = $Vcode->Code;//把隨機數注冊成session //@ob_end_clean(); //清除之前出現的多余輸入 p_w_picpathpng($p_w_picpath);//顯示圖像 p_w_picpathdestroy($p_w_picpath); ?> 以上是vcode.php 不過由于Vcode.class.php我現在還沒弄明白就不寫了。 二:用smarty分離Php和HTML 頁面。 在分離之前先要定義個smarty.php。在里面要用常量定義常用路徑,然后配置smarty ,最后連接數據庫。 <?php /** *名稱:smarty.php *作用:smarty模板配置文件 *說明: *作者:KuaiYigang@xingmo.com *時間:2004-5-22 *更新:2007-8-2 **/ //echo realpath(dirname(__FILE__).'/../'); define ('ROOT', realpath(dirname(__FILE__) . '/../')); require_once ROOT.'/inc/smarty/Smarty.class.php'; //包含Smarty類 $tpl = new Smarty; //創建Smarty類的一個對象 //對Smarty做了一些配置 $tpl -> template_dir = ROOT; //Smarty模板目錄 $tpl -> compile_dir = ROOT.'/tpl_c'; //Smarty編譯目錄 $tpl -> config_dir = ROOT.'/config/smarty'; //Smarty配置目錄 $tpl -> cache_dir = ROOT.'/cache'; //Smarty緩存目錄 $tpl -> left_delimiter = ' right_delimiter = '%>';//右定界符 $tpl->debugging = false;//調試工作臺 $tpl->cache = true;//緩存 $tpl->cache_lifetime = 3600;//緩存時間 if(!defined('SMARTY_DIR')) { define('SMARTY_DIR', ROOT.'/inc/smarty/'); } ?> 三:建立html和php文件,然后在php 文件里包含html文件常用的有 require_once 'common/smarty.php'; $tpl->display('tpl/1.html'); 以上三步就基本結束了,最后要解決的是一些html的問題
轉載于:https://blog.51cto.com/wg168/748913
總結
以上是生活随笔為你收集整理的php培训12.22的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery.protoype.xxx=
- 下一篇: 【转】PHP的异常处理类Exceptio