473,508 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Web Controls

Hey all,

ASP.NET has a concept of a user defined web control, where a person
can implement their own web control and override the render method to
write out html for that control.

I was wondering, in general, do people ever follow a similar pattern
when writing PHP4+ code? By which i mean, i could write a WebControl
base class and a TextBoxControl that inherits from that, then in my
html markup instead of writing out the input tag by hand i could call
textBox->render().

Up to this point i have simply hard coded all the html myself and then
inserted echos into the appropriate places. However, im wondering if
this might be a better approach then having such "messy" html.

Any thoughts? Opinions?

May 2 '07 #1
7 14816
On May 2, 1:02 pm, Areric <josh.schr...@gmail.comwrote:
Hey all,

ASP.NET has a concept of a user defined web control, where a person
can implement their own web control and override the render method to
write out html for that control.

I was wondering, in general, do people ever follow a similar pattern
when writing PHP4+ code? By which i mean, i could write a WebControl
base class and a TextBoxControl that inherits from that, then in my
html markup instead of writing out the input tag by hand i could call
textBox->render().

Up to this point i have simply hard coded all the html myself and then
inserted echos into the appropriate places. However, im wondering if
this might be a better approach then having such "messy" html.

Any thoughts? Opinions?
This is the only thing I miss when I code PHP. ASP.net makes template
logic so much simpler without a few extra tons of code. In PHP, we can
use libraries such as Smarty and others that work similarly to achieve
something similar. In fact, this method at times allows more control
over what goes on than ASP.net controls do.

Here is Smarty template engine, a powerful templating engine that is
basically setting the standard for other engines:
http://smarty.php.net/

And here is TemplateLite, which works almost exactly the same as
Smarty (you barely have to change any code when switching between this
and Smarty), but is better performance-wise. They try to make it so it
can work with the same template files as does Smarty, although
accessing the superglobals works a bit differently. Also, when you
make your own functions, modifiers, and blocks (similar to controls),
the naming convention of the functions is a bit different.
http://templatelite.sourceforge.net/

I think it's good to work with templating engines that work like
Smarty because spin-offs often try to be compatible with it. This way,
if you ever want to switch which your site runs off of, it shouldn't
be too hard.

Mike PII

May 2 '07 #2
Areric wrote:
I was wondering, in general, do people ever follow a similar pattern
when writing PHP4+ code?
Sometimes, sometimes not. They can be useful for projects when you need to
write a lot of forms. For just a small, one-off form though, they're often
more trouble that they're worth.

There are a few pre-written form libraries here:
http://pear.php.net/packages.php?catpid=10&catname=HTML

And I've written one here:
http://demiblog.org/etc/forms

It's good for tab-based forms -- see the comments form on my website. It's
far from complete -- the most significant missing feature is the ability
to feed back error messages from server-side validation. It has a few nice
features though, like client-side validation backed up by revalidation on
the server.

This is somewhat more complete:
http://tobyinkster.co.uk/blog/2005/1...orm-functions/

It's more suited towards long surveys.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 2 '07 #3
Hello,

on 05/02/2007 02:02 PM Areric said the following:
Hey all,

ASP.NET has a concept of a user defined web control, where a person
can implement their own web control and override the render method to
write out html for that control.

I was wondering, in general, do people ever follow a similar pattern
when writing PHP4+ code? By which i mean, i could write a WebControl
base class and a TextBoxControl that inherits from that, then in my
html markup instead of writing out the input tag by hand i could call
textBox->render().

Up to this point i have simply hard coded all the html myself and then
inserted echos into the appropriate places. However, im wondering if
this might be a better approach then having such "messy" html.

Any thoughts? Opinions?
You may want to try this forms generation class. You can develop
plug-ins to implement new behaviors, new validations, new layouts, etc..

http://www.phpclasses.org/formsgeneration
Here you may find several example scripts in action so you can see the
basic form features and several plug-ins:

http://www.meta-language.net/forms-examples.html
Here is a tutorial video explain all the features and some of the
available plug-ins:

http://www.phpclasses.org/browse/video/1/package/1.html

--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
May 3 '07 #4
Thanks all,

Ill check out those various libraries. I once sat down to try and
write my own controls library but really just wondered what it would
gain me. The one nice thing was the ability to use inheritance with
individual controls, so say for example i had a text box control, i
could then derive a numeric text box that did all the validation work
to ensure the user input numeric values. Its a lot more readable than
having a select statement with all the javascript wireup in a million
places.
May 3 '07 #5
On May 3, 12:44 pm, Areric <josh.schr...@gmail.comwrote:
Thanks all,

Ill check out those various libraries. I once sat down to try and
write my own controls library but really just wondered what it would
gain me. The one nice thing was the ability to use inheritance with
individual controls, so say for example i had a text box control, i
could then derive a numeric text box that did all the validation work
to ensure the user input numeric values. Its a lot more readable than
having a select statement with all the javascript wireup in a million
places.
Are form controls the only kind of controls you like to use in
ASP.net?

-Mike PII

May 3 '07 #6
Oh yea, how about Java integration? Maybe you can use JSF UI controls.
They are sort of the Java equivalent of ASP.net controls.

http://php.net/java

-Mike PII

May 3 '07 #7
Areric schreef:
Hey all,

ASP.NET has a concept of a user defined web control, where a person
can implement their own web control and override the render method to
write out html for that control.

I was wondering, in general, do people ever follow a similar pattern
when writing PHP4+ code? By which i mean, i could write a WebControl
base class and a TextBoxControl that inherits from that, then in my
html markup instead of writing out the input tag by hand i could call
textBox->render().
Of course! I call them widgets, here is there class hierarchy:
http://www.phppeanuts.org/site/index...nt.web.widgets

Some special widgets are:
- DialogWidget: holds a reference to an object. It lets the user open a
dialog to search and select an object to reference. To try it out go to:
http://examples.phppeanuts.org/examp...=Employee&id=2
Then click in the widget behind 'country'. After you have selected a
different coutry you will see the widget shows the name of the country
you just selected. If you then press the 'Update' button the form will
be submitted, all it values validated and stored, including the
reference to the county (visitors are not allowed to do this, but if you
enter invalid values the validation will produce error messages)

- MtoNDialogWidget holds references to multiple objects. It lets the
user open an MtoNDialog where the user can add and remove references.
After the dialog is closed the state of the widget reflects the choices
the user made. If you then press the 'Update' button the form will be
submitted, causing the relation in the database to be updated. To try it
out go:
http://examples.phppeanuts.org/examp...=Activity&id=5
and click in the widget behind 'keywords'.

Of course the dialogs hemselves as well as all other pages are built
following the same render pattern, only these are composite
componenents, the composition pattern is explained here:
http://www.phppeanuts.org/site/index_php/Pagina/195

>
Up to this point i have simply hard coded all the html myself and then
inserted echos into the appropriate places. However, im wondering if
this might be a better approach then having such "messy" html.

Any thoughts? Opinions?
It is really worthwile following these patterns, your code becomes much
more readable and you can easily reuse reoccuring components. You do not
need a framework to do so, but if you take time to learn how to use the
framework it may significantly boost your productivity.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.
May 3 '07 #8

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

Similar topics

16
7192
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
2271
by: Mark Johnson | last post by:
Sometimes Controls that have been added to a GroupBox do not show up. What I am doing : 1) I am not using the designer, but create all the Controls per hand: groupBoxProdukt_01 = new...
3
2629
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
1
2116
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
10
5286
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
6
2226
by: dhnriverside | last post by:
Hi peeps, I'm trying to create some controls textboxes at runtime, based on the number of items in a IETreeView that are checked. That I can do, I've got a place holder and I can create the...
66
4057
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
7
2454
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
15
2151
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
8
3561
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
0
7123
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
7382
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...
1
7042
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...
0
7495
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
5627
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,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1556
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 ...
0
418
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...

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.