smarty巧妙處理iframe中內容頁,smartyiframe_PHP教程

來源:互聯網
上載者:User

smarty巧妙處理iframe中內容頁,smartyiframe


做過背景,應該都知道,經常要用到iframe來處理導航,如果按一般的思路來做這個功能,還是挺簡單的

可是當我用smarty的時候,就發現了問題,比如,一個iframeset分成了:頭部top,左邊menu,右邊main,

正常情況,用smarty來處理的話,一般是這樣:

如果3個頁面僅僅只是靜態頁面的話,就是如下處理

iframe.html代碼:





==================================================================

假設iframe裡面的內容頁都要應用到一些特殊處理,如:

top.html需要顯示後台登陸使用者名稱

menu.html中menu都是動態擷取

main.html中需要讀取伺服器的資訊

這樣的話,我們會給3個內容頁分別用3個幕後處理頁

//top.php: $smarty->assign('user', $names ); smarty_Output('top.php') //menu.php: $arr=array(); $arr=GetMenu(); $smarty->assign('menu', $arr); smarty_Output('menu.php'); //main.php $smarty->assign('serverInfo', $serverInfoArr); smarty_Output('main.php'); //顯示iframe頁 smarty_Output('iframe.html')

上面的處理方法,完全能達到要求

iframe.html代碼:





========================================================================

現在我們假設,我們現在要對這3個內容頁分別進行分角色處理,不同角色,3個頁面需要顯示不同的效果

按上面的處理方法,我們就需要對3個頁面分別處理,這樣就自然的就多了冗餘的處理,而且以後的維護也麻煩

於是我想到了下面的方法,獨立出一個專門的處理常式iframe.php,通過條件來類比出上面3個頁面

直接貼代碼了:

iframe.php 後台代碼:

/*此處放共用處理代碼*/

switch($src)
{
case "top":
/*此處放處理代碼*/
smarty_Output('top.html');
break;
case "menu":
/*此處放處理代碼*/
smarty_Output('menu.html');
break;
case "main":
/*此處放處理代碼*/
smarty_Output('main.html');
break;
default:
break;
}


iframe.html:






通過這樣處理,我感覺方便多了

http://www.bkjia.com/PHPjc/1106391.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1106391.htmlTechArticlesmarty巧妙處理iframe中內容頁,smartyiframe 做過背景,應該都知道,經常要用到iframe來處理導航,如果按一般的思路來做這個功能,還是挺簡...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.