In cakephp, I retrieve data from mysql and assign them to an array but i am unable to reuse each element of it in the view.
In the controller i call the model to query data from the database, which have the following format
Array ([0]=>Array([user]=>Array([something]=>somevalue [somethingelse]=>someotherValue))
[1]=>Array([user]=>Array([something]=>somevalue [somethingelse]=>someotherValue))
.......)
and I initilize my ready-to-pass-to-view array as follows, $result is the array obtained from database.
$i=0;
foreach($result as $row)
{
$exportDt[$i]['something']=$row['user'][something];
$exportDt[$i]['somethingelse']=$row['user'][somethingelse];
}
this->set($exportDt);
How can i reuse this exportDt array in the view ? I am thinking that setting is allowed for only one dim array only.
It appears you just need to use the correct syntax for setting the variable (ie passing the variable from the controller to the view):
The first parameter for
$this->set()is the name of the variable that you want accessible from the view. The second is the data to put into that variable.So, for example, you can even use other names:
Another common practice is to use PHP’s
compact. It looks for a variable by the name of the string(s), and creates an array with the name=>valueExample:
More commonly, it’s used with multiple variables: