July 13, 2006

Scaffolding PRADO?

Filed under: PRADO — Marcus @ 12:23 pm

I feel that scaffolding has been one of the biggest pulls for frameworks like Ruby on Rails, Cake, Symfony etc. Obviously the frameworks in question have additional qualities that keep people using them, but the initial “wow, I’ll try that!” factor is gained in those 15 minute movies that have people believing they’ll be creating the worlds next big blog application (is the 15 minute preview video clip that gets youtubed a requirement of Web 2.0?).

http://grahambird.co.uk/cake/tutorials/scaffolding.php is an example of a Cake “get up and create a web application instantly” tutorial. I’m no great fan of the media and journalism in general, so a catchline such as “How to create a working bookmarks manager in less than 5 minutes by using Cake’s scaffolding abilities.” grinds with me a bit because it’s not REALLY a bookmark manager, and it probably won’t take you ONLY 5 minutes… but because I’m not ragging on Cake (I actually do like it, it’s just not my preference), I think the formula presented in that article could be easily applied to a PRADO 15 minute application youtube video. We just need to add a bit of extra functionality in some way…

The article raises 4 points of human provided code to get our super application up and running:

1. Create database table
2. Create the ‘business logic’ behind it (in the article, it’s a REALLY simple model)
3. Create a controller to handle our request and hook up a view to our logic
4. Access the controller and bask on the glory of the next digg

Prado has the View / Controller side of things down pretty well (Prado’s not really MVC, but shares some similar separation points, so I’ll just run with the terminology…), however we need some way to match it up to a Model type class. How do we know when we hit a certain URL that we want to be editing a certain type of business object? I’d probably go with the easiest choice and use the Page name, though you could have some kind of member variable or method used by the parent class to figure out which DB table to use.

So, figuring out which model to be manipulating is easy. How do we hook up a page display to a Model object to a database table? Obviously there needs to be some kind of data mapping separate from our application, but the specifics of that we’ll leave out seeing there’s plenty of good frameworks for it like EZPDO and Propel that can do that for us. So how do we generate an edit view for our pages?

One way is to figure out the types for database field based on their declaration (or, if using EZPDO, their cached classmap), and generate the appropriate components for that class (eg TTextBox for varchar fields, TDatePicker for date fields). Then, on submission of the form, we can easily map these components back into fields in the business object based on the name of the component.

The great thing with Prado is that we can easily provide our own layout template for these type of pages if we like (including validators), making sure that the component’s name matches that of the database field. The event model of Prado means we can intercept the request processing at any point to catch anything before the ’scaffolding’ type functionality takes effect (or even to hook into it directly). One thing I haven’t seen on tutorials like the above link is a quick and easy way to skin / layout the auto mapped controller action. I’m sure it’s not hard, but why isn’t it in those 5 step tutorials? Prado’d make that really simple.

I think, anyway.

Code coming in the next few weeks. Maybe (hopefully…).

June 6, 2006

Prado Components

Filed under: PRADO, PHP — Marcus @ 3:21 am

Because I have nothing better to do (…) I whipped something up for storing prado components: Prado Components. Started when I wanted to learn about Nested sets, and eventually became something usable (well, sort of ;)).

Not for production use yet, but hopefully it’ll get some usage over the next few days.

.

Powered by WordPress