473,770 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Project Design


I am fairly new to PHP and have written an application for managing spam in
a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that generate
blocks of HTML instead of having dynamic elements of PHP inside HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?

Looking forward to reply's!
Rich
--
beep beep
Jul 17 '05 #1
2 1460
Richard Stride wrote:
I am fairly new to PHP and have written an application for managing spam in
a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that generate
blocks of HTML instead of having dynamic elements of PHP inside HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?


Neither!

I use a custom HTML template system, which allows me to write HTML
files (one for each page, or sub-section e.g. a news article template)
completely independently of the PHP code. The HTML contains
placeholders, e.g. {USER_NAME} or {HEADLINE}. I also have a switching
system, so that HTML sections can be blanked out conditionally. Might
look something like:

<DIV>
<H1>{HEADLINE }</H1>
<P>{BODY}</P>
{IS_UGLY?}<P>On e paragraph.</P>{/IS_UGLY?}
{~IS_UGLY?}<P>A n alternative paragraph.</P>{/~IS_UGLY?}
</DIV>

I then have a function which parses the template file, and replaces the
placeholders with strings. So I can just call something like:

parseTemplate(" home.html", array("USER_NAM E" => $userName,
"EMAIL_ADDR ESS" => $email,
"HEADLINE" => $headline,
"BODY" => $newsBody,
"IS_UGLY?" => true));

This may seem like a lot of work to set up, and overkill, and some
might say that it's inefficient at runtime. But from a maintainability
and clarity point of view, it's perfect. There's a sharp interface
between my PHP scripts and HTML design, it's immediately obvious what
variables are going where, and I can design the HTML and PHP completely
separately. And there's no messy nesting of HTML in PHP (so no escape
characters that reduce clarity) or vice versa.

--
Oli

Jul 17 '05 #2
Richard Stride wrote:

I am fairly new to PHP and have written an application for managing spam
in a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that
generate blocks of HTML instead of having dynamic elements of PHP inside
HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?

Looking forward to reply's!


This has been well covered recently and there is a FAQ entry, but here is my
$.02.

The FAQ entry says it best, PHP is itself a templating system, separation of
logic and layout are accomplished by habit and practice, not by technology.

So if you look at templating systems, you will see stuff like:

<h1>{Title}</h1>

Whereas if you just assign pieces of HTML into a lot of variables, you have
this:

<h1><?=$Title?> </h1>

The only difference is that in the second case you don't have to learn a new
language or parse the file.

You can also go the other way in building strings, such as this:

$HTML_BigOutput .= "<h1>".$Title." </h1>"

but I personally have found that cumbersome and problematic.

With all of that said, when we make a page "brandable" we identify the
smallest fragments of HTML that cannot be divided, assign them to
variables, and then include an HTML file, like so:

$Title = "Page Title";
$text = "This is some simple text";
include("HTML_O utput.php");

....and the file HTML_Output.php looks like:

<html>
<head>
<title><?=$Titl e?></title>
</head>
<body>
<h1><?=$Title?> </h1>
<?=$text=?>
</body>
</html>

You can then replace the HTML_Output.php file with something that has
different graphics, placement of objects and so forth.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec )ure(Dat)a(.com )
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
4074
by: nospam | last post by:
THIS IS the DOTNETJUNKIES MESSAGE ------------------------- We're Sorry As many of you know we have recently launched SqlJunkies.com. We have overhauled our runtime and will be using it on DotNetJunkies.com also. -------------------------------------------------------------------------- YEP, DOTNET JUNKIES REDESIGN....
1
3515
by: athos | last post by:
Hi all, Believe you have sound experience in development, however, if we look at the whole Software Development Life Cycle (SDLC) of the project, say, 1. Project Initiation, 2. Gathering Requirements, 3. System Analysis and Design, 4. System Development,
1
2988
by: John Smith | last post by:
Hi, How can I get the project folder programmatically at design time? I'd like to use it in the Forms Designer during dialog design process... And another question... how can I create a custom tabpage inside my custom tabcontrol from the Forms Designer (so that I don't have to modify the code by hand... change the Forms.TabPage to my custom MyCustom.TabPage control).
8
1936
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the folders are actually created in the Solution Explorer so that I can find things easily. Its easy to select multiple files out of a single folder, but not recursively into subfolders. Any ideas? -- Adam Clauss
3
1666
by: John Murray | last post by:
Hi, I'm setting up a project management website, and having a bit of trouble. As part of the site, I have been asked to have a javascript dropdown menu that will open several MS Project (mpp) files. While two of the links work fine, the others do not, and I have absoloutely no idea why. Any suggestions would be greately appreciated. The code I'm working with is:
11
2364
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure similar to a database or XML representation. Rules to modify the stored data will be executed, then the data will be transformed into an output format. Think something similar to FormatA -> XML -> Manipulate XML -> FormatB
3
1962
by: Simon | last post by:
Hi there, my question is not specifically related to C++, but rather the practice around it. I've started a big project in C++ and stumbled onto a couple problems like inter-dependency, forward declarations giving troubles later during compilation and more. All these trouble were mostly due to the design of the files making the whole project. I've read a bit on design patterns but I don't feel I've read enough. I have my project in...
10
3767
by: AG | last post by:
I am trying to use a ReportViewer control in a VS 2005 web application project (not Website project). When I try to create a new report (local), I can't seem to find any method to create a datasource. I would like to use an existing class object. The examples I have found state that the class should be in the App_Code folder. However a WAP does not have an App_Code folder. Is there any way to specify a datasource for a local report in a...
1
1380
by: Tim | last post by:
Dear All, In my opinion, there are so many possible designs for a project, even small up to a class. How can I know which one is better? Is there any important point I should consider in the design? What I should do first for a large project? Design the whole system? or Start a small workable version and then expand? I really need your kind suggestion.
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.