Re: Open Source CMS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 20, 2010 at 08:15:55PM -0800, Allen McCabe wrote:

> For a work in progress, view http://www.mwclans.com/new_index.php
> 
> The login fields are a 'component' I include in the header.
> The links are generated from the 'links' table; the primary_navigation links
> are a class by the same name, and the 'footer_navigation' are also a
> different category. All links on this page are generated from the Links
> table, and each row has 90% of the properties the HTML 'a' tag can have (eg.
> fields: id, link_text, href, target, onmouseover, onmouseout, onclick, name,
> class, etc.). The class is the same as the category.
> 
> The content is pulled from an include file with the same ID number as this
> page ("home" page), which is "1", and the scripts.
> 
> There are additional features, like a theme class which pulls a theme ID
> from the DB (a `site_settings` table).
> 
> Here is an example of the source code for the above link:
> 

You're free to do this as you like, and I've done it in the past just as
you did. But I think the general concensus is that you want to
intersperse as little complicated PHP inside your HTML as possible. For
example, you're doing a database call inside your HTML and then
displaying the results. The more acceptable practice is to make these
calls before you start outputting HTML, shove the values into variables
or an array, and then just loop through the *values* inside your HTML.
There are a couple of reasons for doing it this way. First, anyone
looking at the HTML later who isn't a programmer will have an easier
time of it if there aren't lines and lines of PHP code inside the HTML.
Second, it makes your code more "modular". That is, it puts your main
body of PHP code all together. That aids in debugging, testing and the
like later. This approach means your code is dispersed among several
files instead of just one. But it aids in debugging. I find it painful
to have to scan through HTML for PHP code, so I can fix a problem.

You'll also find that if you have a variety of pages which are all laid
out the same way, it's better to put that HTML in a separate "template"
file. Insert some code in it to display values as needed. Then when you
want to paint a page, simply define the values you want to display, and

include('template.php');

This way, if you make a change to the design or look of the site, you
can make that change to one (template) file and it will echo all over
the site. This is particularly important if you're working with
"designers" who don't know HTML but do the work of designing pages.

This is just simple advice based on my experience. Feel free to ignore
it completely if you work better a different way.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux