[Guide] Explanation of responseView()

Status
Not open for further replies.

Heretic121

OMG Member
Joined
Sep 24, 2010
Messages
446
This is just going to be a quick thread explaining some of things that I've recently worked out about the function responseView.

You can use responseView in any function, but it is needed, as far as I can tell, when you use actionIndex in your ControllerPublic class. responseView returns as an object, which can be saved in a variable and returned later, or just returned straight away. So the if you called:
PHP:
$this->responseView("Test_ViewPublic_Index","test-template",array('testArray'=>''));
It would return:
Code:
object(XenForo_ControllerResponse_View)#30 (6) {   ["viewName"]=>   string(28) "Test_ViewPublic_Index"   ["templateName"]=>   string(11) "test-template"   ["params"]=>   array(1) {     ["testArray"]=>     string(0) ""   }   ["subView"]=>   NULL   ["containerParams"]=>   array(0) {   }   ["responseCode"]=>   int(200) }
It's always useful knowledge to know what functions return and well... now you know :)

Also, you know that array you can return? It's called "params". Well you can use that in your templates.
So if you was to call:
PHP:
$this->responseView("Test_ControllerPublic_Index","test-template",array("testString"=>"Testing"));
And you put this ...
Code:
<div>
  {$testString}
</div>
... in your template named "test-template", then it'll display "Testing" in the new page, or area, you put.

Some useful tips to know. As always, if you have any questions let me know and I'll try to answer them the best I can.
 

dmnkhhn

OMG Member
Joined
Nov 1, 2010
Messages
16
Speaking of saving the responseView return to a variable:

When extending classes it's extremely powerful to inject new params.

Let's pretend you are extending a default controller, inside your method you could do:
PHP:
$returnValue = parent::actionIndex(); // this gives you the viewResponse object
var_dump($returnValue->params); // an array of params that have been passed to the view

You you can extend those params by:
PHP:
$myArray = array('test' => 'wuff', 'bla' => 'notwuff');
$result = array_merge($returnValue->params, $myArray);

return $result; // returns the responseView object with the injected params
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,182
This is a bit over my head, but I learned something here - I just tortured myself figuring out some code of a plugin that wasn't working. But with this thread I actually managed to figure it out and got it to work.

Thanks Heretic and dh.
 
Status
Not open for further replies.
Top