Home >Backend Development >PHP Tutorial >smarty skillfully handles content pages in iframes, smartyiframe_PHP tutorial

smarty skillfully handles content pages in iframes, smartyiframe_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:57:50981browse

smarty cleverly handles content pages in iframes, smartyiframe

Those who have worked in the background should all know that iframes are often used to handle navigation. If you do this according to the general idea The function is quite simple

But when I used smarty, I discovered a problem. For example, an iframeset is divided into: top, menu on the left, main on the right,

Normally, if you use smarty to handle it, it usually looks like this:

If the three pages are just static pages, the processing is as follows

iframe.html code:

<frame src="top.html" name="topFrame" id="topFrame" scrolling="no"><br />  <frameset cols="180,*" name="btFrame" id="btFrame" frameborder="NO" border="0" framespacing="0"><br />    <frame src="menu.html" id="leftbar" noresize name="menu" scrolling="yes"><br />    <frame src="main.html" id="rightbar" noresize name="main" scrolling="yes"><br />  </frameset>

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

Assume that the content pages in the iframe must be subject to some special processing, such as:

top.html needs to display the background login username

The menu in menu.html is dynamically obtained

The server information needs to be read in main.html

In this case, we will use 3 background processing pages for each of the 3 content pages

//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')

The above processing method can fully meet the requirements

iframe.html code:

<frame src="top.php" name="topFrame" id="topFrame" scrolling="no"><br />  <frameset cols="180,*" name="btFrame" id="btFrame" frameborder="NO" border="0" framespacing="0"><br />    <frame src="menu.php" id="leftbar" noresize name="menu" scrolling="yes"><br />    <frame src="main.php" id="rightbar" noresize name="main" scrolling="yes"><br />  </frameset>

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

Now let’s assume that we now want to separate the three content pages into roles. Different roles, the three pages need to display different effects

According to the above processing method, we need to process the three pages separately, which naturally results in redundant processing and future maintenance will be troublesome

So I thought of the following method, independently created a special processing program iframe.php, and simulated the above three pages through conditions

I posted the code directly:

iframe.php background code:

smarty skillfully handles content pages in iframes, smartyiframe_PHP tutorial
/*此处放共用处理代码*/<br /><br />switch($src)<br />{<br />      case "top":<br />         /*此处放处理代码*/<br />         smarty_Output('top.html');<br />         break;<br />      case "menu":<br />         /*此处放处理代码*/<br />         smarty_Output('menu.html');<br />         break;<br />      case "main":<br />         /*此处放处理代码*/<br />         smarty_Output('main.html');<br />         break;<br />      default:<br />         break;<br />}
smarty skillfully handles content pages in iframes, smartyiframe_PHP tutorial


iframe.html:

<frame src="iframe.php?src=top" name="topFrame" id="topFrame" scrolling="no"><br />  <frameset cols="180,*" name="btFrame" id="btFrame" frameborder="NO" border="0" framespacing="0"><br />    <frame src="iframe.php?src=menu" id="leftbar" noresize name="menu" scrolling="yes"><br />    <frame src="iframe.php?src=main" id="rightbar" noresize name="main" scrolling="yes"><br />  </frameset>


By doing this, I feel much more convenient

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106391.htmlTechArticlesmarty cleverly handles content pages in iframes. smartyiframe Anyone who has worked in the background should know that iframes are often used. Handling navigation, if you follow the general idea to do this function, it is quite simple...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn