Jason Purdy wrote:
While I'm thinking about this, what do you guys think about these?

1) Class::DBI Integration
I'm just starting to pick up CDBI (I know, I'm late to the party ;)) and it's kind of frustrating to get the data into the template. Or it could be made easier. I'm not sure if we're talking Plugin or an update to the core, but what would be really cool is to accept CDBI objects in the 'associate' parameter:


$user_record = CDBI::Subclass->retrieve( $primary_key );
$template = $self->load_tmpl(
    'main.TMPL',
    'die_on_bad_params' => 0,
    'associate'         => [ $query, $user_record ],
  );

Not to bring up the old flames :), but many of these issues are because you are using H::T instead of TT ('associate' by the way has nothing to do with C::A. It's an H::T thing). One of the reasons I switched over to TT was because you could pass in objects to the templates and not just scalars and arrays of hashes. This make working with Class::DBI (and any other DAO for that matter) really easy.


Another cool tweak would be to HTML::Template such that you could do a search on the CDBI object and just pass along the results:

@results = CDBI::Subclass->search(
    'year' => '1980'
  );
$template->param( 'results' => [EMAIL PROTECTED] );

This is exactly what you can do *now* with TT. It makes it sooooo easy to take stuff and send it to the template. It also helps with things like dates, times, floating points, etc where you want to choose the format for the display, and the decision is still done in the template, not in the controller.


But one of the nicest things is when you have C::DBI objects that have relationships built in. You can do stuff like this in your template...
[% cd.artist.name %]


and have it traverse the class hierarchy calling the methods that you want it to call. This makes it really easy for instance in a table of search results where you can add a column to the results (as long as the column exists in the database) in your template and you never have to touch the controller.

It could be an easy tweak to the code, where if when trying to fill out a <TMPL_VAR NAME="foo"> from the template's internal param hash or from the associated objects' param methods fail, it will try a last-ditch effort of going through associated objects' methods named after the same parameter name (i.e. foo()).

I had originally thought about trying to write H::T::Obj where you could pass in objects and you could have H::T::O work as sort of a translator between the syntax of the template var tags and the objects provided as params. I still haven't abondoned the idea, but since TT works so well I haven't needed to actually implement it yet.


I know many people don't use TT because other people, IMHO use it badly (ie, putting SQL in their templates, changing the values of variables from within the template, etc). But just because it allows you to do stupid things doesn't mean it's a bad tool. Look at perl. There's a lot of bad perl code. This doesn't mean you should program in java instead.

These thoughts aren't that well-organized, so I hope you get the jist of what I'm aiming for. I'm mostly hoping to instigate some thoughts on how we can get CDBI better supported in cgiapp & htmltmpl. I know we could add a param() method to the CDBI subclass, but that seems kind of a pain to me.

Most of the integration you're talking about, like I said before, does not involve cgiapp (unless I'm missing something). It's all on the H::T side.


I just dug around the htmltmpl list and found this post[1] that's very similiar to what I'm trying to address. Cees (& another poster) says that he adds something to his CDBI subclass, but again, we could do better by centralizing that same code in the htmltmpl core or a plugin, so we don't have to copy/paste that code in every CDBI subclass we have (and just for one app, I have about 6). Cees also points to Template, but I don't see why we can't also have it in htmltmpl. I'm kinda stuck on htmltmpl, personally -- it's very simple and it keeps me from bleeding logic into the template layer of my applications.

I think H::T is great and I was a zealot for a long time. I just like the way that TT handles objects better. That other poster was me, btw :)


2) Status Messages
In an app flow like A -> B -> A, I would like to have a status message on A when B has been successfully processed, but what's the best way to do this? Stuff the message in cgiapp's param? Pass along a param to the runmode method? Then pass that to the template as a param?

That sounds like a reasonable plan to me :)

--
Michael Peters
Developer
Plus Three, LP


--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to