Fandom

Wikia Developers Wiki

Nirvana/WikiaResponse

< Nirvana

908pages on
this wiki
Add New Page
Talk0 Share

WikiaResponse is a [Data Transfer Object]. Any data which is being passed from a Controller into the Template should go through this object.

Important WikiaResponse class features

addAsset()

This is used to add css/sass/javascript to the output (it also supports AssetsManager configured groups/packages). It is a simplified interface to the AssetManager. It is the preferred way right now because it adds things in the proper place based on type and it doesn't require concatenation of global variables on the path.

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

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:

//Controller code to set template variables
$this->stuff = $helper->getStuff();
 
//Template code to use template variable
<?= $stuff ?>

misc functions

  • redirect(), setHeader(), setContentType(), setCode() are all pretty obvious
  • Cache Control. It is possible to control the browser and varnish cache headers
// 1) setting browserTTL is optional, it defaults to the varnishTTL param
// 2) use the constants WikiaResponse::CACHE_LONG, CACHE_STANDARD, CACHE_SHORT
$this->response->setCacheValidity( $varnishTTL, $browserTTL );
  • 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.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.