473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Design methodology question

I am about to embark on creating a mid-size web project that heavily
relies on db interactions.

Since most pages will contain recurring form elements (input text
boxes, dropdown boxes, radio buttons, submit forms, tables, etc.), I am
thinking of using blocks to insert components to each page. All
standard elements would be instances of form element classes. Calling
up these objects would generate customized html code.

Ex: a cbo box could be instantiated in a script via:
<p>Select Customer:</p><?php creatElement($cboName, $cboCSS, $cboVal,
$cboOpt, ..); ?>

Would such an approach be more efficient that the traditional
line-by-line approach wrt. debugging, maintenance, etc. ? (I really
dread mixing php and html.). While I like Smarty's templating approach,
it seems Smarty still requires linear coding to do code translation.

I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?

Thanks for any insights,

Mark

Jun 20 '06 #1
16 1190
ms******@bluewin.ch wrote:
I am about to embark on creating a mid-size web project that heavily
relies on db interactions.

Since most pages will contain recurring form elements (input text
boxes, dropdown boxes, radio buttons, submit forms, tables, etc.), I am
thinking of using blocks to insert components to each page. All
standard elements would be instances of form element classes. Calling
up these objects would generate customized html code.

Ex: a cbo box could be instantiated in a script via:
<p>Select Customer:</p><?php creatElement($cboName, $cboCSS, $cboVal,
$cboOpt, ..); ?>

Would such an approach be more efficient that the traditional
line-by-line approach wrt. debugging, maintenance, etc. ? (I really
dread mixing php and html.). While I like Smarty's templating approach,
it seems Smarty still requires linear coding to do code translation.

I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?

Thanks for any insights,

Mark

This approach is very similar to the Java tag libraries approach. You
may want to check out their design to piggy-back on their experience. I
would suggest that you especially look at the html taglib set.

The lack of polymorphism will be a bit of a hindrance but this can be
worked around by using arrays instead of individual function variables.
For example:
<p>Select Customer:&nbsp;<?php htmlSelect($attributes, $options);?>

Where $attributes is an associative array of tag=value for the
attributes of <select> and $options is an associative array for the
<option> attributes.

-david-

Jun 20 '06 #2
ms******@bluewin.ch wrote:
Would such an approach be more efficient that the traditional
line-by-line approach wrt. debugging, maintenance, etc. ? (I really
dread mixing php and html.). While I like Smarty's templating approach,
it seems Smarty still requires linear coding to do code translation.


That approach sounds good in theory but I've found it doesn't work very
well in practice. User interface tend to require a lot of little
tweaks, sometimes to work around browser difference (layout quirks,
etc.), sometimes just be make things look aesthetic pleasant.
"Shimming" a page, as some might call it. At times it's hard enough to
get one page to look right, let alone trying to make the same piece of
HTML work in multiple locations. A lot depends on how tight a design is
visually. When it's unforgiving, you want to give yourself more
flexibility.

Jun 20 '06 #3
Chung Leong wrote:
ms******@bluewin.ch wrote:
Would such an approach be more efficient that the traditional
line-by-line approach wrt. debugging, maintenance, etc. ? (I really
dread mixing php and html.). While I like Smarty's templating approach,
it seems Smarty still requires linear coding to do code translation.


That approach sounds good in theory but I've found it doesn't work very
well in practice. User interface tend to require a lot of little
tweaks, sometimes to work around browser difference (layout quirks,
etc.), sometimes just be make things look aesthetic pleasant.
"Shimming" a page, as some might call it. At times it's hard enough to
get one page to look right, let alone trying to make the same piece of
HTML work in multiple locations. A lot depends on how tight a design is
visually. When it's unforgiving, you want to give yourself more
flexibility.

Chung:
I was thinking about this at a finer-grained level than you seem to be
in that I was thinking that msch-prv was thinking of automating the
common HTML elements rather than doing something more complex.

While I agree that some sites required a lot of "shimming", those are
also the sites that fall over with every browser upgrade and/or page resize.

Do you think that, say, wrapping <select>, <img> or the various <input>
tags in functions is really going to lead to big layout issues? It seems
to work well enough in the JSP/JSF space...

-david-

Jun 20 '06 #4

<ms******@bluewin.ch> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
I am about to embark on creating a mid-size web project that heavily
relies on db interactions.

Since most pages will contain recurring form elements (input text
boxes, dropdown boxes, radio buttons, submit forms, tables, etc.), I am
thinking of using blocks to insert components to each page. All
standard elements would be instances of form element classes. Calling
up these objects would generate customized html code.

Ex: a cbo box could be instantiated in a script via:
<p>Select Customer:</p><?php creatElement($cboName, $cboCSS, $cboVal,
$cboOpt, ..); ?>

Would such an approach be more efficient that the traditional
line-by-line approach wrt. debugging, maintenance, etc. ? (I really
dread mixing php and html.). While I like Smarty's templating approach,
it seems Smarty still requires linear coding to do code translation.

I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?

Thanks for any insights,

Mark


I create all my HTML through XSL stylesheets which makes building web pages
very easy. All my PHP code has to do is create an XML document with all the
data, and each data field contains instructions on which HTML control is
required for that field. This means that I spend less time in coding screen
layouts and more time in dealing with the important stuff, the business
rules.

Check out the sample application at
http://www.tonymarston.net/php-mysql...plication.html

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org

Jun 20 '06 #5
David Haynes wrote:
I was thinking about this at a finer-grained level than you seem to be
in that I was thinking that msch-prv was thinking of automating the
common HTML elements rather than doing something more complex.
Well, it isn't really automation, since you still need to write the
function call. Basically you're trying to communicate to the computer
that you want an input element at that location. Using HTML as the
language for this purpose guarantees full flexibility. You don't really
gain much using PHP.
While I agree that some sites required a lot of "shimming", those are
also the sites that fall over with every browser upgrade and/or page resize.


True enough. Sometimes you just got to do what you got to do.

Jun 20 '06 #6
Chung Leong wrote:
David Haynes wrote:
I was thinking about this at a finer-grained level than you seem to be
in that I was thinking that msch-prv was thinking of automating the
common HTML elements rather than doing something more complex.


Well, it isn't really automation, since you still need to write the
function call. Basically you're trying to communicate to the computer
that you want an input element at that location. Using HTML as the
language for this purpose guarantees full flexibility. You don't really
gain much using PHP.


I was just thinking about the millions of times I have done something like:

if( ! empty($foos) ) {
printf("<select name=\"%s\">\n", $select_name);
foreach( $foo as $foo ) {
$selected = ($foo['bah'] == 'xxx' ) ? 'selected' : '';
printf("<option value=\"%s\" %s>%s</option>\n", $foo['value'],
$selected, $foo['label']);
}
printf("</selected>\n");
}

and was hoping that it could all be made simpler as something like:
$attributes = array('name' => 'foo');
htmlSelect($attributes, $foo);

in the hopes that the meaning for the page became clearer.

Maybe I'll play with this when I get a little more free time.

-david-

BTW: Why doesn't the foreach() handle the !empty() case? It would make
more sense IMHO.
Jun 21 '06 #7
Let me just say that of all the HTML doofers you can automate, <select>
is the one I have always made work.
I was just thinking about the millions of times I have done something like:
Exactly!


David Haynes wrote: Chung Leong wrote:
David Haynes wrote:
I was thinking about this at a finer-grained level than you seem to be
in that I was thinking that msch-prv was thinking of automating the
common HTML elements rather than doing something more complex.


Well, it isn't really automation, since you still need to write the
function call. Basically you're trying to communicate to the computer
that you want an input element at that location. Using HTML as the
language for this purpose guarantees full flexibility. You don't really
gain much using PHP.


I was just thinking about the millions of times I have done something like:

if( ! empty($foos) ) {
printf("<select name=\"%s\">\n", $select_name);
foreach( $foo as $foo ) {
$selected = ($foo['bah'] == 'xxx' ) ? 'selected' : '';
printf("<option value=\"%s\" %s>%s</option>\n", $foo['value'],
$selected, $foo['label']);
}
printf("</selected>\n");
}

and was hoping that it could all be made simpler as something like:
$attributes = array('name' => 'foo');
htmlSelect($attributes, $foo);

in the hopes that the meaning for the page became clearer.

Maybe I'll play with this when I get a little more free time.

-david-

BTW: Why doesn't the foreach() handle the !empty() case? It would make
more sense IMHO.


Jun 21 '06 #8

ms******@bluewin.ch wrote:
I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?

Thanks for any insights,

Mark


Hmm...

Sounds like Java Gridbag, but for HTML.

Gridbag...or browser quirks and CSS...thats a tough one.

It would be handy to have a gridbag for html, sometimes, though.

Jun 21 '06 #9
Working on my stuff I find programmtically building forms is best on
popups, checkbox lists, and radio lists, where you have multiple
options/selects), using arrays and such you can make it rather clean.
As for miscelaneous text fields most of that stuff as these people say,
is a matter of tweaking.

Larry

Jun 21 '06 #10
David Haynes wrote:
I was just thinking about the millions of times I have done something like:

if( ! empty($foos) ) {
printf("<select name=\"%s\">\n", $select_name);
foreach( $foo as $foo ) {
$selected = ($foo['bah'] == 'xxx' ) ? 'selected' : '';
printf("<option value=\"%s\" %s>%s</option>\n", $foo['value'],
$selected, $foo['label']);
}
printf("</selected>\n");
}

and was hoping that it could all be made simpler as something like:
$attributes = array('name' => 'foo');
htmlSelect($attributes, $foo);
I usually do this:

<select name="something">
<? foreach($foos as $foo): ?>
<option value="<?=$foo?>" <? selected($val, $foo);
?>><?=$foo?></option>
<? endforeach; ?>
</select>

Where the selected() function echo "selected" if the two parameters are
equal. Doing it this way means I can very easily add in a javascript
handler, add an id, specify a class, add a empty item, and so forth.
The loop structure is also flexible. Sometimes I might use a for() loop
instead.

A function that can handle all the possibilities would be rather
complicated. Chances are you won't remember the parameters. This way,
it's just a matter of knowing your HTML. Friendlier for someone who has
to read your code too.
in the hopes that the meaning for the page became clearer.

Maybe I'll play with this when I get a little more free time.

-david-

BTW: Why doesn't the foreach() handle the !empty() case? It would make
more sense IMHO.


Do this:

foreach((array) $clowns as $name => $clown) { }

Null converts to an empty array.

Jun 21 '06 #11
Following on from 's message. . .
I am about to embark on creating a mid-size web project that heavily
relies on db interactions.

Since most pages will contain recurring form elements (input text
boxes, dropdown boxes, radio buttons, submit forms, tables, etc.), I am
thinking of using blocks to insert components to each page. All
standard elements would be instances of form element classes. Calling
up these objects would generate customized html code.


Yes. Good idea.
Similar elements in similar positions with the screen zoned
appropriately.
The second part is getting the data in/out of the database.
Do this by connecting screen objects to the database model.

I've done this for a few years now and what I also have as a result is a
whizzo development system of objects I can stick together on a screen
with a few lines of code to do both screen and db.

Drop me a line(trapped) and you can have the whole code base ready to
run on mySQL.
--
PETER FOX Not the same since the porcelain business went down the pan
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jun 21 '06 #12
Chung Leong wrote:
David Haynes wrote:
BTW: Why doesn't the foreach() handle the !empty() case? It would make
more sense IMHO.


Do this:

foreach((array) $clowns as $name => $clown) { }

Null converts to an empty array.


I hadn't thought of that. Good idea!

-david-

Jun 21 '06 #13
ms******@bluewin.ch wrote:
I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?


I've had success with using PEAR::HTML_Page2 with a few other HTML_*
packages. For example, I have classes that handles Users, and has a
function "getForm". That produces a QuickForm object which I can then
dump into the HTML_Page along these lines:

$p = new HTML_Page2();
....
$u = new User(/* params */);
if ($show_form) {
$p->addBodyContent($u->getForm());
}
....
$p->display();

It took a while to hone this on a bigger scale, but now making GUI
changes is very quick and simple. It has an aditional benefit of not
having to buffer output because everything is inserted into the page
object, and its display is the last part of the script. So I never get
a "header already sent" problem. Anytime before $p->display() you can
re-direct, and do something else.

/marcin
Jun 22 '06 #14

Marcin Dobrucki wrote:
ms******@bluewin.ch wrote:
I visualize html pages in terms of grids where cells could be filled up
by html block components. Is this approach somewhat too fancy?


I've had success with using PEAR::HTML_Page2 with a few other HTML_*
packages. For example, I have classes that handles Users, and has a
function "getForm". That produces a QuickForm object which I can then
dump into the HTML_Page along these lines:

$p = new HTML_Page2();
...
$u = new User(/* params */);
if ($show_form) {
$p->addBodyContent($u->getForm());
}
...
$p->display();

It took a while to hone this on a bigger scale, but now making GUI
changes is very quick and simple. It has an aditional benefit of not
having to buffer output because everything is inserted into the page
object, and its display is the last part of the script. So I never get
a "header already sent" problem. Anytime before $p->display() you can
re-direct, and do something else.

/marcin

IIRC, there is an option in php.ini to automatically buffer output
until flush() or the script ends, also avoid the header already sent
problem.

Jun 26 '06 #15
I agree with Peter, especially on the point that you should use objects
to produce the blocks. Objects are much more flexible then templates and
much more powerfull then simple html. You can make them smart and
adaptive so that you do not have to program a lot to use them. The
phpPeanuts framework is based on this principle too, combined with
simple html-mode php includes for the lay-out rich parts, see
http://www.phppeanuts.org/site/index_php/Pagina/26 for an explanation.

If you don't like the complexity that comes with such a framework, you
can take a look at the 'composition by inclusion and callback pattern',
see http://www.phppeanuts.org/site/index_php/Pagina/195 . The user
interface of the unit testing tool pnt/unit that is included in the
framework download is an example of the application of this pattern, it
does not use framework (except for a tiny not-OO function library).

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Peter Fox wrote:
Following on from 's message. . .
I am about to embark on creating a mid-size web project that heavily
relies on db interactions.

Since most pages will contain recurring form elements (input text
boxes, dropdown boxes, radio buttons, submit forms, tables, etc.), I am
thinking of using blocks to insert components to each page. All
standard elements would be instances of form element classes. Calling
up these objects would generate customized html code.

Yes. Good idea.
Similar elements in similar positions with the screen zoned appropriately.
The second part is getting the data in/out of the database.
Do this by connecting screen objects to the database model.

I've done this for a few years now and what I also have as a result is a
whizzo development system of objects I can stick together on a screen
with a few lines of code to do both screen and db.

Drop me a line(trapped) and you can have the whole code base ready to
run on mySQL.

Jun 26 '06 #16
Henk Verhoeven wrote:
I agree with Peter, especially on the point that you should use objects
to produce the blocks. Objects are much more flexible then templates and
much more powerfull then simple html. You can make them smart and
adaptive so that you do not have to program a lot to use them. The
phpPeanuts framework is based on this principle too, combined with
simple html-mode php includes for the lay-out rich parts, see
http://www.phppeanuts.org/site/index_php/Pagina/26 for an explanation.


You're wrong on that. Just think about a little bit. How could a
hierarchy be more flexible than the free form nature of a language? If
you think so, try to formulate your next sentence in a tree structure.

The success of HTML was not a fluke. The marked up language is a simple
yet very powerful concept. That's why the interface of Mozilla is done
through a marked up language. It's also why the next generation Windows
user interface is based on a marked up language. You know those Vista
gadgets? Powered by HTML.

The widget library is an idea. Marked up language is the future.

Jun 27 '06 #17

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

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
1
by: dwa | last post by:
A general .NET releated design question: Short Verssion: What is the best way to have a data access layer target a different database at run-time, without having to pass in some identifier or...
7
by: NOSPAM | last post by:
I am designing a web application in asp.net C#, and I created classes (in ..cs files) working with the .aspx pages. Now, for database part.... wondering which way is better: 1. put database...
2
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
3
by: C | last post by:
I have been working as a Senir .NET Developer for the past 4 years and worked with VB6 and Classic ASP for 4 years previous to this. I have did an interview recently for an Architect Role. They...
20
by: Brad Pears | last post by:
I am completely new to vb .net. I am using visual Studio 2005 to redo an Access 2000 application into a .net OO application using SQL Server 2000 - so a complete rewrite and re-thinking of how...
2
by: C | last post by:
Hi, I have a Business Requirements Document and Functional Spec from my customer / user. How should I go about approaching the Database Design and Object Model Design? Generally I have done...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
0
by: Gary James | last post by:
I have a question about the methodology used to Serialize / Deserialize objects using XML in .Net 2005 using the v2.0 framework. Say, for example my application creates an instance of Object A,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.