I have a private function which has lots of variables, let's say these: $foo, $bar, $baz.
Inside the function, I call parent::_setViewVars(array('foo','bar','baz'));
This _setViewVars looks so:
protected function _setViewVars($a){
foreach($a as $v){
global $$v;
$this->set($v, $$v);
}
}
I just want to get rid off cakephp's shit like 80 lines of $this->set('selected_areas',$selected_areas);, that's what this function is for.
_setViewVars cannot access $$v, because it's not a global variable. Given that this function is being called from the context that has these variables, can I reach them somehow?
(by the way if there is a cakephp way of bulk setting view variables with the same names, tell me how -- I haven't found one)
PS: packing everything into an array is NOT a solution, we're talking about thousands of unneccessary square brackets here.
compactalso does not reach these variables.parent::_setViewVars? Or skip calling it altogether in favor of your own loop in which you call->set(), dealing with output ofcompact?global? Seriously? Just usecompact()in your controller actions (not in a redundant separate method):$this->set(compact('foo', 'bar', 'baz'));That's btw exactly what CakePHP does when baking controllers...