00001
00034 @endcode
00035
00036 If you want to make sure that your PR2 instance is functional, you should be able to test it by calling:
00037 @code
00038 $prm->renderPrint();
00039 @endcode
00040
00041 It can already build you a page! But that is a pretty boring page. So the next (and most important) subject is...
00042
00043
00044 @section pr2_apiguide_loading Loading Content
00045
00046 As you collect the various components of your page, you will want to load them into named "slots" in the page buffer, which store certain parts of the page. When PR2 renders the page, all those parts will be put together to make a meaningful whole.
00047
00048 @subsection pr2_apiguide_loading_slots Slots
00049
00050 The slots available by default in your output buffer are:
00051 <B>For Page Content</B>
00052 - Main
00053 - SideBar
00054 - ContentWellSideBar
00055 - ContentWellSideBar2
00056 - ContentWellColumn2
00057 - ContentWellColumn3
00058
00059 <B>For the Page Head</B>
00060 - ExtraJS
00061 - ExtraCSS
00062 - Keywords
00063 - ExtraHeadTags
00064 - LibHeadTags
00065 - CustomCSSLinks
00066 - DefaultCSSLinks
00067 - CustomJSLinks
00068 - DefaultJSLinks
00069 - OnLoad
00070
00071 <B>For Page Navigation and Naming</B>
00072 - CollName
00073 - TopBarNavWell1
00074 - TopBarNavWell2
00075 - TopBarNavWell3
00076 - PageName
00077 - PageTitleRightText
00078 - Path
00079
00080 <B>For Tabs Bars:</B>
00081 - TabsBar1
00082 - TabsBar2
00083
00084 <B>For Feature Wells:</B>
00085 - UpperFeatureWell
00086 - UpperFeatureWellColumn2
00087 - LowerFeatureWell
00088 - LowerFeatureWellColumn2
00089 - LowerFeatureWell
00090 - LowerFeatureWellColumn3
00091
00092 <B>For the Bottom Bar</B>
00093 - BottomBarLeftText
00094 - BottomBarRightText
00095
00096 <B>For Metrics Sites</B>
00097 - Omniture
00098 - Analytics
00099
00100 <B>Reserved</B>
00101 - HiddenTempBuffer
00102 - windowTitle
00103 - title
00104 - Flash
00105
00106 Look at the documentation for the SPageTemplate you are using to find out what slots to load your content into.
00107
00108 @subsection pr2_apiguide_loading_simplest The Simplest Page Load
00109
00110 You load content into your page using the load() function, which accepts three parameters:
00111 - <B>$input</B>: a string or object to load into your page
00112 - <B>$options</B>: an associative array of options for how it is to be loaded
00113 - <B>$name</B>: (optional) a name for the load so that you can refer back to it later
00114
00115 In the simplest case, if
00116 - $input is a string in StdXML3 format, and
00117 - you want to load it to the Main (default) slot,
00118
00119 then you can run the following:
00120 @code
00121 $prm->load($input);
00122 @endcode
00123
00124 If your input is HTML instead of StdXML3, you can use the options array to specify that:
00125 @code
00126 $prm->load($input, array('inFormat' => 'html'));
00127 @endcode
00128
00129 @subsection pr2_apiguide_loading_background What Page Loads Do
00130
00131 Every time you call load(), your input content is passed through a translator object. The simplest translator passes content directly to the page without changing it at all. More complex translators can reformat the content or even add interactive features via javascript (such as in-page search).
00132
00133 The translator that PR2 will use is determined by the options you pass to load().
00134
00135 @subsection pr2_apiguide_loading_types Specifying Types When Loading
00136
00137 The translator's input type must match your input, and its output type must match the target format for your output page. The default types are:
00138 - inFormat: xml
00139 - outFormat: html
00140
00141 You can indicate that your input is something other than the default type by passing an option to the load function, as we saw above. This code snippet is simply telling PR2 that the input string is HTML rather than the default, XML.
00142 @code
00143 $prm->load($input, array('inFormat' => 'html'));
00144 @endcode
00145
00146 @subsection pr2_apiguide_loading_translators Specifying Translators When Loading
00147
00148 PR2 chooses its translators based on their input and output types. If the input type of your content changes, so does the default translator. For every type, there is a default translator. Shown below are the default translators for each type:
00149 xml: STransStdXML3
00150 html: STransHTML
00151 object: STransObject
00152
00153 So, when you specify inFormat to be html, PR2 simply chooses the STransHTML translator and passes your input through that.
00154
00155 You can pick which translator is used by changing the option specifying which translator handles your type of input. You simply change the value for the option <tt>translator_type</tt> (where type is your input type) to the translation class you want to use. The translator can either be a default translation class (in common/pr2/translate), or a custom translation class (in project/app/translate).
00156
00157 Below is an example of picking the STransBookXML class to translate your input XML. Note that specifying inFormat to be xml is unnecessary as xml is the default inFormat.
00158
00159 @code
00160
00161 $prm->load($input, array('inFormat' => 'xml', 'translator_xml'=>'STransBookXML'));
00162
00163
00164 $prm->load($navXML, array('inFormat' => 'xml', 'translator_xml' => 'STransNavXML'), 'Nav');
00165 @endcode
00166
00167 @subsection pr2_apiguide_loading_targets Specifying Targets When Loading
00168
00169 One more thing you are likely to change in the load options is the target of the translation: the slot in which the output content should end up.
00170
00171 The option for the translation target is <tt>trans_target</tt>. Simply specify a slot name for this option, and the content will be added to that slot rather than to the Main (default) slot.
00172
00173 For instance, the following code would use the default translator for HTML (STransHTML) and would direct its output to the SideBar slot in the page buffer.
00174 @code
00175 $prm->load($input, array('inFormat' => 'html', 'trans_target' => 'SideBar'));
00176 @endcode
00177
00178 @subsection pr2_apiguide_loading_modes Specifying Modes When Loading
00179
00180 Finally, a seldom-changed option, you can change the mode of the load so that the translator overwrites the content of the slot rather than appending to it (the default). We could modify the last code sample to "set" rather than "append" as follows:
00181 @code
00182 $prm->load($input, array('inFormat' => 'html', 'trans_target' => 'SideBar', 'trans_mode' => 'set'));
00183 @endcode
00184
00185 @subsection pr2_apiguide_loading_tk2 Loading TK2 Objects
00186
00187 You'll often want to load TK2 view objects to your PR2 page. This is done with the add() function as follows:
00188 @code
00189 $prm->add(new TKLabel('Hello, World!'));
00190 @endcode
00191
00192 Of course, you can add any TK2 view to your PR2 page, no matter how complex. You can also pass the standard translator options to the add function. For example, if we wanted to load the TK2 item into the SideBar:
00193 @code
00194 $prm->add(new TKLabel('Hello, World!'), array('trans_target' => 'SideBar'));
00195 @endcode
00196
00197 @subsection pr2_apiguide_loading_snap2 Loading SNAP2 Content
00198
00199 It is frequently useful to display SNAP2 content through a PR2 page. Therefore, PR2 auto-detects SNAPResource and SNAPVersion objects when they are passed to load() to make things super-easy. For example:
00200 @code
00201 $s = Snap2::lookup('
00202 $prm->load($s);
00203 @endcode
00204
00205
00206 @section pr2_apiguide_layout Page Layouts and Templates
00207
00208 PR2 layouts and templates define how the page content, stored in slots, will be combined to form an output page.
00209
00210 - A page layout writes the actual HTML code for one type of page design
00211 - A page template determines what chunks or "meta-slots" of the page layout show up, in what order, and with what internal design
00212
00213 To make your page be a typical Shodor-style page, set your page layout to SShodorLayout. This layout class knows how to write out the HTML for all possible parts of a Shodor-style page. (You don't need to do this in your code, since it is the default layout.)
00214 @code
00215 $prm->setOption('layout', 'SShodorLayout');
00216 @endcode
00217
00218 Then, if you want to re-order, hide, or change the style of the meta-slots, you can use a page template. For instance, to choose a template that hides the PageTitle and PathBar, shows the UpperFeatureWell, sets the UpperFeatureWell to display as two columns, and sets the ContentWell to display with a right side bar, you could use the template called SplashPageTwoColsRightSideBar:
00219 @code
00220 $prm->setOption('template', 'SplashPageTwoColsRightSideBar');
00221 @endcode
00222
00223 Layouts and templates are documented on a class-by-class basis. Some templates may only look good for certain layouts. For instance, the PrintTemplate looks good under SShodorLayout, but not HPCULayout.
00224
00225 In addition to using globally available layouts and templates, you can extend them to create local layouts and templates in your own project. You can extend SShodorLayout (or SLayout) and SPageTemplate and store your classes in app/layout and app/template. If you are doing this, be sure to add those folders to the search path using SAutoLoad::addSearchPath().
00226
00227
00228 @section pr2_apiguide_rendering Rendering and Printing
00229
00230 The final step in using PR2, after loading your content in, is to render the page (combine all the slots into a meaningful page using a layout/template) and print the page buffer to the screen.
00231
00232 This can all be done using the renderPrint() command:
00233 @code
00234 $prm->renderPrint();
00235 @endcode
00236
00237
00238 @section pr2_apiguide_misc Other Miscellaneous Functions
00239
00240 Often, you want to exit out of a PR2 page that you are in the process of building because some fatal error has occurred (for instance, a user has passed the script invalid input or tried to access a page for which he/she does not have permission).
00241
00242 In these cases, it is useful to use the flashAndExit() function to render and print a pretty error page and then exit the script immediately. Here's an example:
00243 @code
00244 if($error) {
00245 $prm->flashAndExit('You made my program angry! Goodbye.');
00246 }
00247 @endcode
00248
00249 @section pr2_apiguide_summary Summary
00250
00251 Here's a sample controller script that fetches XML from a file and content from SNAP2, then loads them both into the content of a page. It assumes we are in a project with a standardIncludes file.
00252 @code
00253 include_once("../../config/standardIncludes.php5");
00254
00255 /* create your page */
00256 $prm = new PageRender2();
00257
00258 /* load in your static XML content */
00259 $xml = file_get_contents("$PROJECT_ROOT/content/sampleList.xml");
00260 $prm->load($xml);
00261
00262 /* load in your SNAP2 content */
00263 $rsrc = Snap2::lookup('
00264 $prm->load($rsrc);
00265
00266
00267 $prm->renderPrint();
00268 @endcode
00269
00270 @section pr2_apiguide_extending Extending PageRender2
00271
00272 Most projects have a local version of PageRender2 that defines special behaviors for rendering. For instance, you might want to change some of PR2's options site-wide, or you might want to override the renderPrint() function so that some last-minute items are added to your page right before it gets printed out.
00273
00274 Here is the default LocalPageRender2 provided by the sherpa site template. In this class, the local PR2 overrides the constructor to set the collection name slot to the name of the project at the time the PR2 instance is created. This value could be changed in the code as the controller runs.
00275
00276 It also overrides renderPrint() so that it can generate and add the navigation XML to the page at the last minute. This allows controllers to keep modifying/adding items to their NavXMLModule until the moment the page is rendered to the screen. This allows pages to add tabs, etc. more easily.
00277
00278 @code
00279 class LocalPageRender2 extends PageRender2 {
00280
00281 public function __construct() {
00282 global $SITE_PATH, $PATH, $STRING;
00283 parent::__construct();
00284 // get the page of this PR2 and set the default Collection Name
00285 // to be the full name of this site.
00286 $this->getPage()->setSlot('CollName', $STRING['siteName']);
00287 }
00288
00289 public function renderPrint() {
00290 global $snm;
00291 // load the site nav before rendering and printing any page
00292 if (isset($snm) and ($snm instanceOf NavXMLModule)){
00293 $nav = $snm->generateXML();
00294 $this->load($nav, array('translator_xml'=>'STransNavXML'), 'Nav');
00295 }
00296 parent::renderPrint();
00297 }
00298 }
00299 @endcode
00300
00301 These are the most frequent reasons for extending PageRender2, but there are many other possibilities!
00302
00303 */