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:
/*此处放共用处理代码*/<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 />}
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