
The fourth step of creating a presentation application is to map data services to the presentation layer using PHP. Given a particular set of input DataRSS, you must specify PHP code to map that data to different components of a PHP associative array. This step is the heart of your data service.
Modify Appearance — Specifies PHP code
that maps DataRSS to different components of the presentation
application, such as the title or the thumbnail picture. The code
consists of a single public static function named
getOutput(). This function must return an associative array with a particular
structure that defines the presentation application's.
Within getOutput(), you can define the
associative array using any PHP code you like, subject to the
restrictions of the “SearchMonkey PHP Whitelist”. However, the
most common pattern is to use simple assignment. The Data helper class, which
represents the DataRSS XML provided by your selected data services,
provides three static functions for retrieving individual components
from your DataRSS: Data::get(), Data::xpath(), and Data::xpathString(). There are
also three static functions for retrieving common icons: Data::getImage(), Data::getStars(), and
Data::getStarsFromNum().
![]() |
Note |
|---|---|
Always try to use Data::get() before resorting to Data::xpath() or Data::xpathString(). Data::get() is easier to use, and it tends to be more robust if the underlying XML structure happens to change. You should only use the XPath functions if you have a problem that requires the full power of the DOM. |
For most presentation applications, the PHP consists of simple
assignments using Data:get():
public static function getOutput() {
$ret = array();
/* Key Value pairs - up to 4 */
$ret['dict'][0]['key'] = "Text";
$ret['dict'][0]['value'] =
Data::get('review:Review/review:text');
$ret['dict'][1]['key'] = "Review";
$ret['dict'][1]['value'] =
Data::get('review:Review/review:rating');
/* More assignments ... */
return $ret;
}
To help make development even easier, SearchMonkey provides a
list of DataRSS components to the right of the PHP textarea.
Clicking the button generates the
correct Data::get() call for retrieving that component.
The generated Data::get() functions should suit the
requirements of most SearchMonkey applications. However, if you
require arbitrary XPath expressions, you can use Data::xpath().
By default, the textarea is populated with skeleton PHP code
that lists all of the different array elements that presentation
applications can use. Use the skeleton to assign values to the
elements that you want to add or customize. ("I want three links, a
customized title, and a thumbnail.") After assigning values using
Data::get() or other means, you may delete the
"leftover" array keys.
![]() |
Tip |
|---|---|
|
While you can use the provided textarea to develop your PHP code, you are also welcome to use your own editor or IDE, particularly if your application is doing something more complicated than simple key/value assignment. All user PHP code is run inside a class. If you write your
own functions, you must call them using
|
![]() |
Caution |
|---|---|
Computationally-intensive PHP may cause Enhanced Result applications to dynamically displayed in Infobar style, in order to provide users with fast access to basic search results. Once your application is cached, it may revert back to an Enhanced Result. |
For detailed explanations of all the elements of the PHP array, refer to “Presentation Application PHP Structure”. For guidelines about how to design your application, refer to “Presentation Application Best Practices”.
— Saves your changes and continues to “Step 5: Confirmation”.
— Saves your changes and returns to “Step 3: Data Services”.
— Returns to the Application Dashboard.
At the bottom of the screen is the Preview Pane, which displays the results of your data service for one of your test URLs.
If all is well, the Preview Pane should display the actual enhanced search result that your presentation application would produce for the given test URL. If there are any problems with the display code, the Preview Pane displays a bulleted list of warnings and errors.
The Preview Pane contains several controls for cycling through your test URLs and determining your data inputs and outputs:
— Saves any changes to
your PHP and calls your presentation application again, displaying
the results in the Preview Pane. When you click
for the first time,
SearchMonkey fetches content for all of your test URLs, which can
cause a delay and a "Loading, Please Wait"
message.
— Displays a link to the URL being tested. The link opens the test URL in a new window. Use this option to verify that your presentation application is displaying the correct data for the correct page.
— Cycle the Preview Pane through your test URLs.
— Indicates which URL of
the total N is being tested.
You can jump to any test URL by clicking on the corresponding
dot.M
— Displays the DataRSS content for the URL being tested in a new window. Use this option to verify that the input DataRSS has the structure that you think it does.
— Displays the actual PHP array
returned by getOutput() for the URL being tested in a
new window. Use this option to verify that your presentation
application is producing the proper
array for display.