Re: best way for PHP page



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

.



Relevant Pages

  • Re: nested conditional that can identify parent page?
    ... and specify the files in the array including ... try to make as little php and html mix as possible, have a template ...
    (alt.php)
  • Re: A better XSS trap (Feedback wanted)
    ... better to always be forced to choose the right filter depending on the ... It makes template code shorter, ... and easier to understand for non-programmers (doing the HTML design). ... I personally stick to PHP only, because the I gain of a template engine ...
    (comp.lang.php)
  • Re: Separation of logic, design and data
    ... That is the weakness of using includes for HTML pieces. ... <?php include 'headerstuff.php'; ?> ... and now I'm here at my Template ... I'm sure at some point in the future I'll see the weaknesses in my ...
    (comp.lang.php)
  • Re: How do we get there from here?
    ... > then sub the whole of that generated markup into the template? ... layed out on the fly, a simple IMG tag, or even an entire HTML document. ... PHP scripting provides 10 times the features of both of these ... idea as tokens can eliminate a huge amount of maintance, ...
    (comp.databases.pick)
  • Re: query string passing woes........ help... please....
    ... |> | offer any help other than saying that my validation could be FAR more ... I'm a total newbie at php. ... The easiest way for you would be to make the html form called form.php ... $_SESSION array using the same names. ...
    (alt.php)