smarty cleverly handles the code of content pages in iframe_PHP tutorial

WBOY
Release: 2016-07-21 15:20:35
Original
882 people have browsed it

Without further ado, let’s get to the point
Those who have worked in the backend should all know that iframe is often used to handle navigation. If you follow the general idea to do this function, it is quite simple
But when I use smarty For example, an iframeset is divided into: head top, left menu, right main,
Normally, if you use smarty to handle it, it usually looks like this:
If the three pages are just For static pages, the
iframe.html code is processed as follows:

Copy the code The code is as follows:




< frame src="main.html" id="rightbar" noresize name="main" scrolling="yes">


Assume that the content pages in the iframe are Some special processing needs to be applied, such as:
top.html needs to display the background login user name
The menu in menu.html is dynamically obtained
Main.html needs to read the server information
like this If so, we will use 3 background processing pages for 3 content pages respectively
Copy code The code is as follows:

// 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');
//Display iframe page
smarty_Output('iframe.html')

The above processing method can fully meet the requirements
iframe.html code:
Copy code The code is as follows:







Now we assume that we now need to process these three content pages separately. Different roles, the three pages need to display different effects.
According to the above processing method, we need to process the three pages separately. Processing, so naturally there will be more 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 through conditions The code is posted directly on the page
:
iframe.php Backend code:
Copy code The code is as follows:

/*Put shared processing code here*/
switch($src)
{
case "top":
/*Put processing code here*/
smarty_Output('top. html');
break;
case "menu":
/*Put processing code here*/
smarty_Output('menu.html');
break;
case "main":
/*Put processing code here*/
smarty_Output('main.html');
break;
default:
break;
}

iframe.html:
Copy code The code is as follows:







By doing this, I feel much more convenient

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325060.htmlTechArticle Without further ado, those who have worked in the backend should know that iframe is often used to handle navigation. , if you follow the general idea to do this function, it is quite simple. But when I use...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!