Re: [Phplib-users] Odd PHPlib WebApp Problem
Brought to you by:
nhruby,
richardarcher
From: Andrew C. <ph...@ev...> - 2004-05-10 19:59:48
|
Ah! That makes sense. It sounds like a much better approach to using nested templates. I was really disappointed when this popped up. I have been striving to keep my code, content (in a database), and formatting (in templates and CSS) completely separate. I'm not sure if this will have any impact on the immediate problem but, it does address a larger concern. Thank you, Andrew Crawford At 12:56 AM 5/8/2004 -0500, Layne Weathers wrote: >Quoth Andrew Crawford: > > > The table is complicated enough that the users need the column headers > > reproduced every 5 or 10 records to make it usable. Originally, I was > > generating this view entirely using nested templates. The view took way > > too long to load - over 80 seconds - and monopolized the server's CPU for > > the entire time. Several users even had timeout problems waiting for the > > page to load. Benchmarking revealed almost all of that time was spent in > > the section that output the column headers every few records. > > >Whenever I use nested templates, I hand the nested part off to a clean >template object, build the full list, and hand the parsed content back to >the primary template object. I often do this several times in one page. > >The problem is that when you use your global template object, the regular >expression tries to replace all known variables on each parse(). The fewer >variables used in your nested block, the greater the speed gain of this >method. > >It might be worth a try. > > >I've added a shortcut function to my Template extension class that I call >before each nested block to start with a clean loop template object: > function unset_vars() > { > $this->varkeys = $this->varvals = array(); > } > >Here is a simple sample building the options in a select: > > $loop_tpl->unset_vars(); > $loop_tpl->set_var("option", "\n <option >value=\"{value}\"{selected}>{text}</option>"); > > foreach($options as $text => $value) > { > $loop_tpl->set_var(array( > "value" => $value, > "text" => $text, > "selected" => ((is_array($some_var) and ($value == $some_var)) ? >" selected" : ""))); > $loop_tpl->parse("options", "option", true); > } > $tpl->set_var("options", $loop_tpl->get_var("options")); > >Layne Weathers |