[eluser]Thatch[/eluser]
Ok, I've painted myself into a corner it seems and If could get a bit of help I would appreciate it.
I have a controller where one function in accessing another function, passing a $data array between the functions to collect the needed data. (this is for a pchart implementation). I'm getting all the data I need as I check the array after each call of the secondary function. $data is passing some configuration info to the chart building function before returning the data. I'm echoing it out at the end of each pass and this is what it looks like (so you've got an idea of what I'm doing)
Array ( [woot] => wooogie [count] => 1 [percents] => Array ( [0] => 19 [1] => 34 [2] => 13 [3] => 20 [4] => 10 [5] => 4 ) [legend] => Array ( [0] => one [1] => two [2] => tree [3] => four [4] => five [5] => six ) [title] => Title 1 [image1] => Array ( [name] => /system/application/charts/pie-WiTA9WhBbHGtTufY.png [w] => 403 [h] => 297 ) ) 1
Array ( [woot] => wooogie [count] => 2 [percents] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 45 [5] => 45 ) [legend] => Array ( [0] => one [1] => two [2] => tree [3] => four [4] => five [5] => six ) [title] => Title 2 [image2] => Array ( [name] => /system/application/charts/pie-Mzo1MEPvmkKp1NDK.png [w] => 403 [h] => 297 ) ) 2
Array ( [woot] => wooogie [count] => 3 [percents] => Array ( [0] => 15 [1] => 20 [2] => 25 [3] => 10 [4] => 10 [5] => 10 ) [legend] => Array ( [0] => one [1] => two [2] => tree [3] => four [4] => five [5] => six ) [title] => Title 3 [image3] => Array ( [name] => /system/application/charts/pie-b4c0eESTR1wvp1Oq.png [w] => 403 [h] => 297 ) ) 3
last before view
Array ( [woot] => wooogie [count] => 3 [percents] => Array ( [0] => 15 [1] => 20 [2] => 25 [3] => 10 [4] => 10 [5] => 10 ) [legend] => Array ( [0] => one [1] => two [2] => tree [3] => four [4] => five [5] => six ) [title] => Title 3 [image3] => Array ( [name] => /system/application/charts/pie-b4c0eESTR1wvp1Oq.png [w] => 403 [h] => 297 ) [overview] => report_view [altama] => altama_view )
----------------------------------------
You'll see that the 'last before view' print_r shows only the last image added. I ran into the same issue with 'count' where I couldn't update the contents of 'count' within the external function. A similar thing is happening here where the previous 2 image additions are dropped.
I'm sure this is a basic issue of understanding how to use Arrays between functions but I just can't figure out what I need to do here. I'm not sure I've explained it well, if not let me know and I'll give it another shot.
Any help you can offer would be greatly appreciated.
[eluser]danmontgomery[/eluser]
I don't really understand the question... Are you saying "last before view" should contain all of the arrays, not just the last one? Maybe you should post some actual code?
[eluser]InsiteFX[/eluser]
From the looks of it, your over writing the array each time.
You can try the array merge using different array's through
each function/method.
Code: <?php
$array1 = array();
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
?>
Enjoy
InsiteFX
[eluser]Thatch[/eluser]
You know I thought at first I was over writing but each array for the image information in numbered and those show up properly when I print the array.
I grabbed the code and pared it down some so that perhaps it will make more sense...
Code: function buildPie($data)
{
$this->load->library('charts');
$config = array(
'SpliceDistance'=>10,
'TitleFontSize' => 16,
'TitleFontName' => 'pf_arma_five.ttf');
$percents = $data['percents'];
$legend = $data['legend'];
$title = $data['title'];
$bottom_label='bottom label';
$i = $data['count'];
$data['image'.$i] = $this->charts->pieChart(100,$percents,$legend,'',$title,$bottom_label,$config);
return $data;
}
function results()
{
$data['count'] = 0;
$data['percents'] = array(19,34,13,20,10,4);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 1';
$data['count']++;
$onion = $this->buildPie($data);
$data['percents'] = array(1,2,3,4,45,45);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 2';
$data['count']++;
$onion = $this->buildPie($data);
$data['percents'] = array(15,20,25,10,10,10);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 3';
$data['count']++;
$onion = $this->buildPie($data);
$this->load->view('includes/template', $onion);
}
You'll see that I am adding to 'count' in the original function as this would not update when I tried to increment it inside the buildPie function (where it makes much more sense to be).
Thanks for the assistance so far.
[eluser]InsiteFX[/eluser]
Code: function buildPie($data)
{
$this->load->library('charts');
$config = array(
'SpliceDistance'=>10,
'TitleFontSize' => 16,
'TitleFontName' => 'pf_arma_five.ttf');
$percents = $data['percents'];
$legend = $data['legend'];
$title = $data['title'];
$bottom_label='bottom label';
$i = $data['count'];
$data['image'.$i] = $this->charts->pieChart(100,$percents,$legend,'',$title,$bottom_label,$config);
return $data;
}
function results()
{
$data['count'] = 0;
$data['percents'] = array(19,34,13,20,10,4);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 1';
$data['count']++;
$onion1 = $this->buildPie($data);
$data['percents'] = array(1,2,3,4,45,45);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 2';
$data['count']++;
$onion2 = $this->buildPie($data);
$data['percents'] = array(15,20,25,10,10,10);
$data['legend'] = array('one','two','tree','four','five','six');
$data['title'] = 'Title 3';
$data['count']++;
$onion3 = $this->buildPie($data);
$onion = array_merge($onion1, $onion2, $onion3);
$this->load->view('includes/template', $onion);
Not tested but you can try the above.
Enjoy
InsiteFX
[eluser]Thatch[/eluser]
thanks Insite. I'll give that a shot.
Can anyone explain why passing the array around like I was doing doesn't work? The fact that I was inserting image1 and then image2 (and so on) would seem to restrict any overwriting. I'm just missing why that wouldn't work.
|