Table of Contents
When a user adds a container rule, they are automatically prompted to
select a display template (this is discussed earlier in this guide). In order
to render your container rule, the run()
method is
executed (covered below), then the chosen template is rendered.
public function run(Module_Pages_ClientRenderer_PageRequestTree $pageRequestTree)
Throws Exception
This method is executed prior to rendering the container rule with the chosen template. This allows you to make any data available to the template as required.
Take the weather container rule driver we've been developing in this guide. In this situation you would determine the weather for the chosen location, then assign it to the view. The view is what controls the display of a template. You can assign any data to it, all of which is available from the template.
You can access the view from the run()
by calling $this->getView()
.
You can then assign any data as required.
In order to access the location value that is stored with the container rule (defined when the user
added the container rule), you must access the rule and corresponding parameter. You can firstly
calling $this->getRule()
to retrieve the rule, then getParam()
to get the value.
The following listing shows an example of this. It generates a fake weather report assigns it to the view (obviously to be of real use it would contact some weather service with the location to get the real data).
Example 4.1. Running a container rule
<?php class Driver_containers_rule_weather_controller extends Module_Containers_Driver_Abstract { // ... public function run(Module_Pages_ClientRenderer_PageRequestTree $pageRequestTree) { $rule = $this->getRule(); $location = $rule->getParam('location'); $data = array( 'location' => $location 'day' => 'Monday' 'temp' => '30 Celsius' ); $view = $this->getView(); $view->weather = $data; } // ... } ?>