Not a bug  Extending an action with a return of ControllerResponse_View

Jeremy

in memoriam 1991-2020
OK,

Here's a confusing on. Mike sorta knows the situation. For my add-on BB Code Manager I needed to extend XenForo_ControllerPublic_Help. According to Mike, if I did:
PHP:
public function actionBbCode()
{
     $var = parent::actionBbCode();
     $var->params['addMyTemplateVar'] = 'Hello';
     return $var;
}

That it'd work. In essence, this sorta did. It added addMyTemplateVar to the params array just fine. However, it seems that it rendered the view already, so it produced a display error (since I was using it in a foreach()). Now, my next "solution" was to do that, then create a new ResponseView with the $params again. Now, this worked, but it didn't have mediaSites defined in $var->params. Which it should, if I was correct (I had some guidance from Mike here)? Here's my final code:
PHP:
	public function actionBbCodes()
	{
		$viewParams = parent::actionBbCodes();
		$viewParams->params['mediaSites'] = $this->getModelFromCache('XenForo_Model_BbCode')->getAllBbCodeMediaSites();
		$viewParams->params['customBbCodes'] = $this->getModelFromCache('KingK_BbCodeManager_Model_CustomBbCode')->getAllActiveCustomBbCodes();

		return $this->_getWrapper('bbCodes',
			$this->responseView('XenForo_ViewPublic_Help_BbCodes', 'help_bb_codes', $viewParams->params)
		);
	}

So my solution was to ad to $var->params[] the ['mediaSites'] again using the model call found in parent. But, again, this is basically what I hard originally started with. Maybe params[] was the wrong variable to use, but I basically end up with the same code I started with, just with a more unreadable sense: the 'copied' code from XenForo. Maybe a bug? Maybe not? Maybe just using the wrong variable?
 
Assuming you want to make available a variable in the original template help_bb_codes;
Have you tried doing something like: (untested)
PHP:
public function actionBbCode()
{
	$wrapper = parent::actionBbCode();
	$wrapper->subView->params['addMyTemplateVar'] = 'Hello';

	return $wrapper;
}
 
Yes in this particular instance, there's a sub-view. The outer view is the wrapping template. I haven't tested it, but Shadab's code should be correct.
 
On a side note, if you're struggling with figuring out what things are, you can use Zend_Debug::dump($var); to get a var_dump (that you can view more easily). That style of debugging is very very common in the PHP world (there are proper debuggers as well, but that depends on your IDE and your level of comfort with using them).
 
I use Panic's Coda, so I have no real debugger... And thanks for the help you guys (again, to you Mike!). Zend_Debug::dump() may REALLY really help me in the future, and I'll be using that a lot. :P
 
Top Bottom