Subject Re: [firebird-php] Jumping in the wagon
Author Milan Babuskov
Alexandre Benson Smith wrote:
> I have let WEB development aside because I think it's good for browsing
> data but has a very poor interface regarding data entry, to get anything
> close to the experience provided by a desktop app, one need to do a lot
> of code in Javascript, use DHTML a lot and so on, things that I always
> think to be extremely more time consuming to do the same in a Delphi app
> for example. Now we have AJAX in the game

To be honest, AJAX was there years ago, but nobody knew about it until
Google Mail showed up one day.

> to master, but the time has come, I think I need to dirty my hands, and
> put my old brain to learn new technologies (let's see if an old dog can
> learn new tricks ! :-) )

It should be piece of case to learn AJAX, I did in one day (with all my
previous knowledge of JavaScript and other related technologies.

> I think the only reliable way to learn anything new is to develop
> something real, I get bored easily and tend to abandon the project if
> it's just "for fun" or just a simple test without any real benefit/value
> for me.

I'd recommend a smaller project to start with, especially if you're
going to start from scratch. I wrote my first 'framework' back in 2002
for a smaller (~30 tables) application. The second one came just a year
later on a big (100+ tables) application. In the smaller one I learned
all the DOs and DON'Ts. Last year I developed a comletely new framework
(MVC this time) and I'm sure this one is here to stay. I even rewrote
that first application to it, in about a week.

Just like Alan, I started when there were no frameworks and AJAX around
(even CSS was considered 'advanced' usage then), and I wrote my own. My
framework is about 3500 lines of PHP and JS code, broken in 5-6 mostly
independent files, so I don't have more than 50-60k of PHP code for web
server to chew on for each request.

> Should I start from beginning using a framework ?
> Should I start from beginning using a template class ?

I'm not sure. I depends on the kind of applications you want to develop.
If it's ERP, maybe it's better to start from scratch (I do CRM/ERP
mostly). I'm not very experienced with frameworks and have no time to
learn one now, so I might be biased (a lot).

> Should I start with a basic interface (HTML only), or should I start
> from the beginning using Ajax and DHTML ?

DHTML and AJAX from the start. You can't make a mistake there. Just make
sure you don't overdo it with AJAX, as it can be tempting. There are
things AJAX is good for (saving bandwidth and increasing interactivity)
but it has drawbacks (harder to debug, breaks the Back button in
browser). My rule of thumb is to use AJAX whenever I feel that plain
DHTML is too restrictive for the user of too inefficient (for example,
loading a 500kB page into browser just to hold some info for JS
functions is not a good idea).

> I am afraid of adopting a Framework

The biggest problem with that is that you would need to understand how
it works, and why it works that way. Without some developing 'on your
own' it would be hard.

> I think that reading those books give me a brief overview about the
> whole thing, but I don't think that neither are good examples of doing a
> real project using PHP, all the rules and presentation are mixed
> together, that does not look the way it should be. I understand that
> both books are introductory, but I think it should introduce in the
> right way :-)

Well, I can tell you how my framework looks like:

For each entity (for example goods, customers, etc.) I have a model
expressed in PHP variables and arrays that describes database tables and
field involved, their descriptions, foreign key lookup fields, custom
formatting of dates and numbers, types of HTML controls used to entry
data, dataset filter rules and JOIN rules for each table. Well, it's
actually much more detailed, but it would be too much to type it all here.

This model is not created by hand (although one could). I wrote a small
generator that loads the tables, fields and their relations from the
database (by reading Firebird system tables) and pre-builds the initial
model for me. Then I just open it with PHP editor and change the stuff
that is custom (for some tables I don't even change anything).

I also have a representation model (currently only one though) that
dictates the page layout: buttons, grids, links in the grid (you can
click on almost anything and get more details), filter/search boxes,
navigation elements, etc.

The framework engine loads those and creates DHTML pages. I mostly use
two kinds: one with grid view, filtering and navigation and other with
form view for adding/modifying data. For foreign key lookups on large
tables I use AJAX. There is also a support for master-detail
relationships (ex. invoice data and items). It also has all the little
details: requires not null fields, formats date, time and numbers after
the entry (I wrote some JS code for that), has a DHTML date picker, etc.

I used GET for all the data requests and POST for all the data 'writes'.
This enables the user to bookmark some view on his data, for example:

http://localhost/pro/query.php?def=EMPLOYEE&st=NAME&sp=CONTAINING&v=alex

> On the past, the tests I had did looks like the same of the presented on
> the books, and that is what I always think was wrong with my "projects",
> I need the parts clearly separated (presentation and logic), I think the
> MVC is the way to go.

After going through 3 different frameworks, I completely agree. Once you
create a good MVC base you can develop applications rapidly.


--
Milan Babuskov
http://www.guacosoft.com