2014-04-15

← Older revision

Revision as of 18:30, April 15, 2014

Line 1:

Line 1:



WikiaResponse is a [[http://martinfowler.com/eaaCatalog/dataTransferObject.html| Data Transfer Object]]. Any data which is being passed from a Controller into the Template should go through this object.

+

WikiaResponse is a [[http://martinfowler.com/eaaCatalog/dataTransferObject.html Data Transfer Object]]. Any data which is being passed from a Controller into the Template should go through this object.

 

 

 

==Important WikiaResponse class features==

 

==Important WikiaResponse class features==

Line 7:

Line 7:

 

 

 

<syntaxhighlight lang="php">

 

<syntaxhighlight lang="php">



$this->response->addAsset('extensions/wikia/Foo/css/Foo.scss' );

+

$this->response->addAsset( 'extensions/wikia/Foo/css/Foo.scss' );

 

$this->response->addAsset( 'extensions/wikia/Foo/js/Foo.js' );

 

$this->response->addAsset( 'extensions/wikia/Foo/js/Foo.js' );

 

$this->response->addAsset( 'oasis_shared_js' );

 

$this->response->addAsset( 'oasis_shared_js' );

 

</syntaxhighlight>

 

</syntaxhighlight>

 

 



===getData() setData()===

+

===getData() setData()===

 

The main function of this DTO is to maintain an array of data. If you need to get at that or set all the data at once, use these helpers. Generally the main access point for data is in the Controller class where individual fields are set through the magic __set helper on the Controller, which automatically adds to the WikiaResponse data object which is automatically exported into the template. For example:

 

The main function of this DTO is to maintain an array of data. If you need to get at that or set all the data at once, use these helpers. Generally the main access point for data is in the Controller class where individual fields are set through the magic __set helper on the Controller, which automatically adds to the WikiaResponse data object which is automatically exported into the template. For example:

 

 

 

<syntaxhighlight lang="php">

 

<syntaxhighlight lang="php">



//Controller code to set template variable

+

//Controller code to set template variables



$this->stuff = $stuff;

+

$this->stuff = $helper->getStuff();

 

 

 

//Template code to use template variable

 

//Template code to use template variable

Line 28:

Line 28:

 

* Cache Control. It is possible to control the browser and varnish cache headers

 

* Cache Control. It is possible to control the browser and varnish cache headers

 

<syntaxhighlight lang="php">

 

<syntaxhighlight lang="php">



$this->response->setCacheValidity( 3600, 3600, array(

+



WikiaResponse::CACHE_TARGET_BROWSER,

+

// 1) setting browserTTL is optional, it defaults to the varnishTTL param



WikiaResponse::CACHE_TARGET_VARNISH,

+

// 2) use the constants WikiaResponse::CACHE_LONG, CACHE_STANDARD, CACHE_SHORT



));

+

$this->response->setCacheValidity( $varnishTTL, $browserTTL );

 

+

 

</syntaxhighlight>

 

</syntaxhighlight>

 

* render(), toString(), printText() are all helpers used by Ajax entry points and shouldn't be used directly without good reason. Render a View, not the Response.

 

* render(), toString(), printText() are all helpers used by Ajax entry points and shouldn't be used directly without good reason. Render a View, not the Response.

Show more