Re: Best practices for php application

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Brent Baisley <brent@xxxxxxxxxxxx>:
> On Oct 21, 2004, at 12:47 PM, abrea wrote:
> > Dear list,
> > Does anybody know of a url where I can find reading materials about
> > best practices to organize the filesystem and variable structure of
> > a php application?  Although application purposes probably vary
> > widely, I imagine that in one way or other most include adding,
> > updating, deleting and displaying records, so there might be some
> > standard or preferred procedure.
> 
> That's a whopper of an open ended question. I found the biggest help 
> for me was reading up on the MVC (Model, View, Controller) technique, 
> which is probably the most commonly used "design pattern" for just 
> about any language.

Hear, hear! I first ran into this pattern when programming in Perl -- I
stumbled across CGI::Application, tried it out, and wondered how anybody
would program any other way. (Obligatory self-promotion: I've since
ported it to PHP -- http://freshmeat.net/projects/cgiapp/ ). 

For the OP, the basic idea behind an MVC pattern is: 

* Model -- separate code that deals with manipulating your data store
  into classes or distinct functions grouped in a file
* View -- separate code that deals solely with presentation logic ("if
  the user is an administrator, show these links; otherwise, show
  these") into files of their own (or use a template engine)
* Controller -- separate code that deals with user input and validations
  into a controller.
 
Typically, your controller is either the actual script for the
application or a class that can be invoked with metadata (read:
customizable applications!). It then takes input, validates and filters
it, and passes it to the Model code. The data it receives back from the
Model is either piped directly back to the View, or acted upon and
further transformed before doing so. 

Learning to program this way is difficult at first -- it's a far cry
from opening a file, writing out a few statements, and executing it.
However, the flexibility it affords, and the maintainability, are
invaluable.

I'm not sure of any URLs to give the OP. I'd highly recommend "The
Pragmatic Programmer", by Hunt and Thomas (Addison Wesley Press).
Another place to look might be the Horde's CVS collection -- to see how
other PHP programmers do it.

-- 
Matthew Weier O'Phinney           | mailto:matthew@xxxxxxxxxx
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux