RE: [Phplib-users] (no subject)
Brought to you by:
nhruby,
richardarcher
From: Brian P. <bp...@ct...> - 2001-10-08 15:00:04
|
Another way is to embed these calls into regular functions. The OO in = PHP leaves much to be desired because all functions are public. Because of = this, when you override any class, you risk stepping on the author's toes = later. Granted, it's not likely the author(s) would ever add an = apply_defaults() function to Template class, but I think functions are more = understandable anyway. On my site, I do something like this at the top of every page: =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= include "../globals.php"; my_page_open(); /* PHPLib wrapper function */ my_header( "BPopp Sanctuary" ); /* Loads my common headers, menus, = etc. /* .. content goes here my_footer (); my_page_close(); exit; =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= my_header () would look something like (in it's simplest form): function my_header ( $title ) { $t =3D new Template (ABSOLUTE_ROOT); /* ABSOLUTE_ROOT is the path to the site and is 'defined' in globals.php */ $t->set_file ( "main", "header.html" ); $t->set_block ( "main", "HEADER" ); $t->set_var ( "title", $title ); $t->pparse ( "out", "HEADER" ); } -----Original Message----- From: Jens Benecke [mailto:je...@je...] Sent: Sunday, October 07, 2001 8:50 AM To: php...@li... Subject: Re: [Phplib-users] (no subject) On Sat, Oct 06, 2001 at 10:49:50PM -0600, Roberto Mello wrote: > I'm starting to use phplib, mainly for its DB, Cart and Template = classes. > Great work by the way. :-) I like them as well. =20 > On the template class, is there a way to have "master" templates for = the > whole site, that would be included in all other templates? It seems = to me > that by having to specify the root in every templated page, it = wouldn't > allow that functionality out of the box. Well, there's OOP for you : simply extend the Template class. Put your default settings in the extended class definition, perhaps in the constructor. (Don't forget to call the inherited constructor.) I've = done this at www.hitchhikers.de, the navigation bar, stats and banner parts = are all automagically generated when I do $t =3D new hhsession; $t->vars[TITLE] =3D "different page title"; $t->apply_defaults(); > Has someone done that? Yes. :-) class hhtemplate extends template { var $vars =3D array( TITLE =3D> "Hitchhikers"; # ... ); # ... function hhtemplate($root=3D"tpl/", $foo=3D"remove") { $this->Template($root, $foo); # call the original constructor # ... some more settings } =20 # ... default / additional functions } --=20 Jens Benecke =B7=B7=B7=B7=B7=B7=B7=B7 http://www.hitchhikers.de/ - = Europas Mitfahrzentrale Crypto regulations will only hinder criminals who obey the law. |