I'm new to CakePHP and I'm looking at some code I've downloaded that has a function that looks like this:
$this->set(array('fruit' => 'orange', 'vegetable' => 'kale'));
In the code, the array variables are accessed in another controller function using this method:
$varsSet = $this->viewVars;
echo $varsSet['vegetable'];
What I'd like to do access the array variables in the same function in the controller where the $this-set() statement is made, and it seems like I should be able to do so with just one line of code. I've tried all of the following:
echo $fruit;
echo $this->field('fruit');
echo $this->MyModel->$fruit;
echo $this->MyModel->field('fruit');
And all of these throw parse, undefined variable, or variable not found errors. What would be the simplest/most proper way to access the variable within the same function in the controller?
Thanks,
Jonathan