LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Sunday, April 30. 2006

What is Cgiapp?

After some conversations with Paul and Mike, in recent months I realized that while I often announce new releases of Cgiapp, I rarely explain what it is or why I develop it.

I got into trouble on the PEAR list when I tried to propose it for inclusion in that project, when I made the mistake of describing it as a framework. (This was before frameworks became all the rage on the PHP scene; PEAR developers, evidently, will not review anything that could possibly be construed or interpreted as a framework, even if it isn't.) I mistakenly called Cgiapp a framework once when considering proposing it to PEAR. But if it's not a framework, what is Cgiapp? Stated simply:

Cgiapp is the Controller of a Model-View-Controller (MVC) pattern. It can be either a front controller or an application controller, though it's typically used as the latter.

As a controller, it provides some basic, configurable routing mechanisms to determine what should be displayed for a given request, a simple registry for configuration variables and for passing variables around between method calls, error handling, hooks into a template engine, and hooks into pre/post application and request operations.

When developing applications using Cgiapp, you operate on the idea of one display screen, one method. You define a hash table mapping display screens to methods, and either indicate a query parameter or a segment of the request URI that will indicate the display requested; when the request comes in, the appropriate method is called. In Cgiapp terms, these are called "run modes".

What makes Cgiapp so enticing for me as a developer?

  • Object orientation. Cgiapp is inherently object oriented; to use it, you must create a class that extends Cgiapp (or Cgiapp2!), and map methods to actions. There's no getting around it. Because of this, applications are namespaced, portable, and testable.
  • Reusability. Because each application is a class, and each application instance is triggered from an instance script, and because you may pass configuration variables to the class from the instance script, Cgiapp-based applications are inherently reusable. This makes it easy to distribute applications, as well as to reuse them in multiple site locations. As an example, I have used article applications in multiple locations, accessing different article stores -- but using the same article application class. Each had a different look and feel, sometimes within the same site, sometimes in different sites, but I merely needed to change the data store and the templates to achive the differentiation.
  • Extensibility. Ever code something, and then need an application that duplicated much of the functionality, but added some twists to it? One such example: I had a small gallery application, and later needed an e-card application. The latter was basically a gallery type of application, but when selecting an image, needed to display an e-card form, and also needed to handle the results of that form. I simply had the e-card class extend the gallery class, added a method, and created a new view template for the image view. Total extra work: about an hour or so.
  • Developer freedom. Because Cgiapp is not a framework, and, indeed, only a single class (that changes in Cgiapp2, but only because Cgiapp2 has some helper classes), it gives a lot of freedom to the developer. You can pick and choose what templating system you want to use. Or what data storage mechanism you want to use. Or how you'll handle sessions. Or whether you'll use pretty urls or GET parameters (or allow one, but default to the other). In a nutshell, it allows the developer to cherry pick the libraries and components they want to use in their application.

It's the last point, above, that really separates Cgiapp from most other MVC frameworks I've reviewed. Most frameworks tend to give you everything, package it up, and try to sell it to you as the developer: "Use only the tools integrated in our solution, we can't guarantee best performance otherwise." Cgiapp doesn't do that. Cgiapp let's the developer call the shots and say, "I'm familiar with such-and-such library and want to use that in my MVC application," or, "I like such-and-such template engine, and want to use that," or, "I need my application to work regardless of whether mod_rewrite is available." As examples, I've done extensive development with Cgiapp that used Smarty and PEAR::DB; I've also used Savant and Zend_Db. I have users that report they love ADODB. I've used pretty URLs, but I've also often used GET or POST to determine the current run mode. The point is, Cgiapp merely provides an easy to use controller into which you can plug the model and view of your choice.

The other very important aspect of Cgiapp, to me, is application reusability. With Cgiapp2, this becomes even more of a feature, as applications can be customized via run-time plugins from the instance script. If an application has to be tied to a particular site structure, it's never completely reusable. But when it is configurable per instance, via templates, data store, and/or pre/post operation actions, it becomes distributable and pluggable. This means the possibility of applications like forums, galleries, contact forms, article systems, etc. that can be dropped in anywhere in a site and easily configured to match that site's look and feel. To me, this is invaluable.

With this explanation of Cgiapp under my belt, I plan to start blogging about uses of Cgiapp and Cgiapp2 to show how it can most optimally used. In the meantime, feel free to comment and ask questions!

Update: Changed language in third paragraph to put emphasis on Cgiapp as not a framework instead of anti-PEAR slant.

Posted by Matthew Weier O'Phinney in PHP at 09:54 | Comments (4) | Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

"PEAR developers, evidently, will not review anything that could possibly be construed or interpreted as a framework, even if it isn't."

We review individual components, as the basic idea behind PEAR is to provide small, reusuable components. We told you that in our answers to your proposal.

You asked:
"Could somebody succinctly (and authoritatively) explain why PEAR "isn't a place for framework[s]"?"

How can you expect anyone to see your proposal as anything else as a framework?

I also quickly read the code and I fully agree with the other pear devs (who answered in the list), that does not fit in pear.

I also wonder what brings such class, but this is a personal taste matter :-)
#1 Pierre on 2006-04-30 15:37 (Reply)
Pierre, I should not have made the incendiary remarks about PEAR here, as they detract from the point of my entry. The point is not to attack the PEAR development process, but to define what Cgiapp is.

As for where Cgiapp came from, it's a port of CGI::Application, a perl module. That's clear from both the class file itself, as well as the Cgiapp website. It's stated in all my release notes.

Contrary to what you write, Cgiapp is not a framework. I have no desire to maintain a framework. It is a Controller, plain and simple. You can write your Model and View using whatever libraries you want, PEAR, ezcomponents, Zend Framework, Solar, whatever, and still use Cgiapp as your Controller.

And, no, nobody once in the thread you reference referred to my code, only to my description of it. My last post in that thread explained how Cgiapp is a controller, not a framework, and I had no replies to that message. In fact, regarding your statement:

"We review individual components, as the basic idea behind PEAR is to provide small, reusuable components. We told you that in our answers to your proposal... how can you expect anyone to see your proposal as anything else as a framework?"

I actually brought up the argument that Cgiapp itself fits perfectly in those criteria. It is itself a small, reusable component. It is not a framework. It encourages cherry-picking the components you need in order to build an application.

But this is all water under the bridge. Cgiapp exists on Sourceforge now, and it will stay there for the forseeable future.
#1.1 Matthew Weier O'Phinney (Link) on 2006-04-30 17:22 (Reply)
Also, as reference, your post and the thread:

http://marc.theaimsgroup.com/?l=pear-dev&m=111318619622872&w=2
#2 Pierre on 2006-04-30 15:38 (Reply)
If it is just a controller then I see no reason why it could not make it into PEAR :-)
#3 Arnaud on 2006-05-02 07:37 (Reply)

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back November '08 Forward
Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

November 2008
October 2008
September 2008
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml dojo
xml dpc08
xml file_fortune
xml linux
xml mvc
xml oop
xml pear
xml personal
xml php
xml phpworks08
xml programming
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net