Re: best way for PHP page
- From: Kenoli <kenoli.p@xxxxxxxxx>
- Date: Wed, 2 Jan 2008 08:52:03 -0800 (PST)
I do something similar to Sancar. However since I like to work with a
WYSIWYG html editor and work with other colleagues who have no php
experience and are involved in designing our pages, I like to use
template files like:
(I think this gives the idea; sorry for errors in details as I kind of
threw this together.)
template.php
<html>
<style>[include css files or styles]</style>
<head.
<title><?=$title ?></title>
</head>
<body>
<div><? getPageBlock($page, 'left', otherVariables); ?></td></div>
<div><? getPageBlock($page, 'right', otherVariables); ?></td></div>
</body>
</html>
and include in a functions.php file functions like:
function getPageBlock($page, $column='left', $otherVariable1,
$otherVariable2) {
$_REQUEST['$page'], ['$column'], ['$otherVariable1'];
otherFunction($otherVariable2); }
I create every page on the site with a function like:
function createPage($title, $page, $otherVariables) {
include(' functions.php');
[other includes];
include('template.php');
}
I could imagine that if one were familiar with OOP it might be
efficient to put all of this into a Class definition. Others with
more experience also will probably have ideas for making it more
efficient as procedural script as well. I'm kind of new at this.
I also try to avoid tables and separate out html formatting into CSS
files. It is sometimes useful to determine which CSS files are
included based on input from a php script.
I can then call the template from a function feeding the title and any
other variables into the page or the functions called from the page,
while working with the template as an html file. I can also edit any
data called by the getPageBlock functions as pure html and save them
in a data base to be called and inserted into the template.php page by
those functions. This lets me treat main or sub templates as html and
completely change the page layout without affecting the content. It
also has the advantage of allowing others managing content to do that
by updating the content database from a web browser.
I can build an entire page using very few files: one or more
templates, a single file that calls all pages in the site based on php
variables, and subsidiary css, php and javascript include files.
This creates lots of flexibility. I can also change the links on any
page by applying them via a single function from link lists selected
from a database. I use a javascript (or php) function to dynamically
highlight the active link on any given page.
This pretty much separates php from the html and page content and
style from the html part of the page structure.
It might be noted here that there are issues here that involve
managing a number of elements, including style or design(CSS),
structure (html), page content (text, images, sound, calculated data,
etc.), server side interactivity (php/mysql), client side
interactivity (javascript) and client/server interactivity (AJAX).
And there are many instances when these elements interact with or even
modify each other.
Figuring out how to isolate and manage these elements independently
has been a key to my learning more about how to work with all of them.
Incidentally, I have found that building web sites on my own using the
various coding structures was easier than learning a content
management system and lets me design web sites that don't look like
they were cut from a cookie cutter as well as serving the exact
functions I want to serve.
--Kenoli
On Jan 2, 12:16 am, sancar.sa...@xxxxxxxxxx (Sancar Saran) wrote:
Hello,
I believe TYPO3 has good implementation about splitting code and template.
And to archieve clean php code.
1-) Left <html> <?php echo $this; ?></html> model development
2-) Find good template engine. (no not that smarty, it was too big)
3-) use strict dicipline to move html to outside of the code.
Also if you can use the php based template files you can lift off the template
overhead.
like.
template.php
$strPage = "
<html>
<head.
<title>".$strPageTitle."</title>
</head>
<body>
<table>
<tr>
<td>".$strLeftBlock."</td>
<td>".$strRigthBlock."</td>
</tr>
</table>
</body>
</html>";
process.php
$strPageTitle = getPageTitle($_REQUEST['page']);
$strLeftBlock = getPageBlock($_REQUEST['page'],'left');
$strRightBlock = getPageBlock($_REQUEST['page'],'right');
include('template.php');
echo $strPage;
regards
Sancar
.
- References:
- best way for PHP page
- From: "Alain Roger"
- Re: [PHP] best way for PHP page
- From: Sancar Saran
- best way for PHP page
- Prev by Date: Re: [PHP] best way for PHP page
- Next by Date: automatic caller
- Previous by thread: Re: [PHP] best way for PHP page
- Next by thread: Re: [PHP] best way for PHP page
- Index(es):
Relevant Pages
|