smarty巧妙处理iframe中内容页的代码

废话不多说,进去正题
做过后台的,应该都知道,经常要用到iframe来处理导航,如果按一般的思路来做这个功能,还是挺简单的
可是当我用smarty的时候,就发现了问题,比如,一个iframeset分成了:头部top,左边menu,右边main,
正常情况,用smarty来处理的话,一般是这样:
如果3个页面仅仅只是静态页面的话,就是如下处理
iframe.html代码:

复制代码 代码如下:


<frame src="https://www.jb51.net/top.html" scrolling="no">
<frameset cols="180,*" frameborder="NO" framespacing="0">
<frame src="https://www.jb51.net/menu.html" noresize scrolling="yes">
<frame src="https://www.jb51.net/main.html" noresize scrolling="yes">
</frameset>


假设iframe里面的内容页都要应用到一些特殊处理,如:
top.html需要显示后台登陆用户名
menu.html中menu都是动态获取
main.html中需要读取服务器的信息
这样的话,我们会给3个内容页分别用3个后台处理页

复制代码 代码如下:


//top.php:
$smarty->assign('user', $names );
smarty_Output('https://www.jb51.net/top.php')
//menu.php:
$arr=array();
$arr=GetMenu();
$smarty->assign('menu', $arr);
smarty_Output('https://www.jb51.net/menu.php');
//main.php
$smarty->assign('serverInfo', $serverInfoArr);
smarty_Output('https://www.jb51.net/main.php');
//显示iframe页
smarty_Output('iframe.html')


上面的处理方法,完全能达到要求
iframe.html代码:

复制代码 代码如下:


<frame src="https://www.jb51.net/top.php" scrolling="no">
<frameset cols="180,*" frameborder="NO" framespacing="0">
<frame src="https://www.jb51.net/menu.php" noresize scrolling="yes">
<frame src="https://www.jb51.net/main.php" noresize scrolling="yes">
</frameset>


现在我们假设,我们现在要对这3个内容页分别进行分角色处理,不同角色,3个页面需要显示不同的效果
按上面的处理方法,我们就需要对3个页面分别处理,这样就自然的就多了冗余的处理,而且以后的维护也麻烦
于是我想到了下面的方法,独立出一个专门的处理程序iframe.php,通过条件来模拟出上面3个页面
直接贴代码了:
iframe.php 后台代码:

复制代码 代码如下:


/*此处放共用处理代码*/
switch($src)
{
case "top":
/*此处放处理代码*/
smarty_Output('https://www.jb51.net/top.html');
break;
case "menu":
/*此处放处理代码*/
smarty_Output('https://www.jb51.net/menu.html');
break;
case "main":
/*此处放处理代码*/
smarty_Output('https://www.jb51.net/main.html');
break;
default:
break;
}


iframe.html:

复制代码 代码如下:


<frame src="https://www.jb51.net/iframe.php?src=top" scrolling="no">
<frameset cols="180,*" frameborder="NO" framespacing="0">
<frame src="https://www.jb51.net/iframe.php?src=menu" noresize scrolling="yes">
<frame src="https://www.jb51.net/iframe.php?src=main" noresize scrolling="yes">
</frameset>


通过这样处理,我感觉方便多了

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a53e3484b31c779275266154b088c0c5.html