Re: PHP web design patterns



I just realized I think I was designing an Observer pattern into a
part of a script I am designing. I need to display certain qualities
when displaying records of people depending on the context. Thus I
might have a set of radio buttons where the user clicks on one to
determine the context. As soon as that happens, the disply changes to
associate the appropriate data with each person given the selected
context. AJAX provides a way of producing this change immediately.
I'm realizing that as well as changing the displayed data, a different
algorithm could be called, thus processing the same or a different set
of data in a different way depending on the need of the "subject" (to
use observer pattern terminology).

I think this latter dynamic is what is called the strategy pattern,
actually.

Seems like AJAX is particularly suited to these patterns, as,
otherwise, the state change is not observed until a submit is made in
addition to the state change. In the MVC model, no change is really
expected until a submit is made.

In this case, I am applying it to a part of the site. My sense is
that it is hard to apply any of these patterns in a "pure" way
throughout a site. Life is complex and subtle, factors engineers
often lose in an abstract quest for definitive models.

--Kenoli

On May 18, 2:54 pm, steve <s...@xxxxxxx> wrote:
On Sat, 19 May 2007 02:33:05 +0800, kenoli wrote
(in article <1179513185.241010.75...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>):



This doesn't get to your question in an abstract way because I am just
learning the concept of patterns, and may not get to it at all, but it
is my experience with structuring php scripts. I've been coding for
acouple of years, off and on, because of a need to have an interactive
web application for a project I am involved in. I suspect that while
I have used various scripting structures, they all more or less fall
under the the MVC model.

I started out trying to keep pages organized into several categories:
those that are mostly html, includes that provide libraries of
functions and, my goal, one script that handles all the processing.
This latter involved a lot of switches and other control structures to
get the data processed appropriately. This pretty much followed the
MVC pattern, the html pages being the view and the processing script
being the control. I designed my database, I guess you would call
this the M part, based on a conceptual analysis of my project needs
and some guidelines from "Database Design for Mere Mortals," which I
found to be a very useful book.

Over time, I found my processing script growing to a size that it was
hard to manage. I faced more and more challenges regarding how to
send my html data to the right parts of the script. What I finally
resolved to, which serves me pretty well now, is a model where the
script that processes an html page is placed between php tags at the
head of the document. The html on that page, which I try to keep as
pure html as possible, is placed "below" the script tags and any
action it triggers refers back to the same page, activiting a switch
or some control mechanism to process the data appropriately. Once the
data is processed, the user is sent to the same or another html page
as appropriate, sending along any necessary data in post, get or
session variables.

I'm finding myself modfiying my database schema as we use the
application and as I see how it interacts with my scripting needs.
Thus it is being modified to adapt to practical scripting issues and
to the end use requirements. In this way I provide increased
flexibility and efficiency all all levels.

As my scripts develop, I find ways to reuse them and re-organize them
so that they are growing into modules and more readable scripts.

This seems to be a useful development model for me, though it may not
work for an enterprise sized application or a design project involving
a team of developers.

I am not doing OOP, though I am looking into it. I'm not sure there
are advantages for the size of the project I am involved in. I use my
functions and includes in a similar way to which one might use objects
and have thought about experimenting with developing them into
objects.

I'm very interested in other responses to your query.

--Kenoli

On May 17, 2:27 pm, anal_aviator <analavia...@xxxxxxxxxxxxxx> wrote:
Hi,
I'm looking to develop a web-site with both database and php access.
Personally I'm familiar with the MVC design pattern , are there any quick
pointers on other suitable patterns, that will cover both web & database?

Yes thanks for the reply.
As you point out other responses will be interesting. I was looking for
people not using the MVC , basically to get an idea of what they were doing
as regards the web project and any experiences they had.

I was also looking at the Observer Design pattern, however it appears some
patterns Can be applied globally to a site , whereas others specifically
target given areas.


.