This shows you the differences between two versions of the page.
quickstart [2014/04/02 17:00] 82.35.30.20 |
quickstart [2014/04/05 02:52] (current) 81.187.95.96 old revision restored |
||
---|---|---|---|
Line 25: | Line 25: | ||
<code xml><p>Hello <em tal:content="who_to_greet"/>!</p></code> | <code xml><p>Hello <em tal:content="who_to_greet"/>!</p></code> | ||
+ | ===== Gathering of data ===== | ||
+ | This is not a requirement, but good advice: avoid passing PHPTAL object (or template abstraction wrapper) around your entire program. MVC programs should be independent of their views (mental exercise: would your application break if there was no view?). | ||
+ | |||
+ | Instead of setting variables directly on PHPTAL object, make your methods //return// all required information. You can also pass helper objects to PHPTAL which will load data on demand. | ||
+ | |||
+ | <code php><?php | ||
+ | $result_array = execute_my_page(); | ||
+ | $result_array['logged_in_user'] = find_logged_in_user(); | ||
+ | $result_array['sidebar'] = new SidebarHelper(); | ||
+ | |||
+ | $phptal = new PHPTAL($page_template); // create PHPTAL object *after* getting data | ||
+ | |||
+ | foreach($result_array as $k => $v) $phptal->set($k,$v);</code> | ||
===== Layout template ====== | ===== Layout template ====== |