0
votes

i have this code.

function index(){
    $this->load->helper('url');
    $this->load->view('EIM/home');
        $this->loadGraphs();
}

but it executes loadGraphs first. I really have no idea why. Please help me. I'm having a hard time fixing my codes. thanks :)

here is my loadGraphs function:

`function loadGraphs(){ $this->load->helper('url'); $ctr=0; $base_url = base_url(); $xml=new DOMDocument; $xml->load("".$base_url."assets/EIM/xml/defaultChart.xml"); $module_names=$xml->getElementsByTagName("name"); $len_modules=$module_names->length; $ctr_module=0; while($ctr_moduleitem($ctr_module)->getElementsByTagName("report"); $len_reports=$reports->length; $ctr_report=0; while($ctr_reportitem($ctr_module)->getAttribute("value"); $title=$reports->item($ctr_report)->getElementsByTagName("title")->item(0)->nodeValue; $dashboard_selected=$reports->item($ctr_report)->getAttribute("id"); if($dashboard_selected=="dashboard"){ echo " $title $module"; ?> var parameters=eval(getArray($title,$module));?>) item($ctr_report)->getElementsByTagName("charts")->item(0)->getAttribute("value"); $defaultChart=$reports->item($ctr_report)->getElementsByTagName("charts")->item(0)->getAttribute("value"); echo "$defaultChart"; $charts=$reports->item($ctr_report)->getElementsByTagName("charts")->item(0)->getElementsByTagName("chart"); $len_charts=$charts->length; $ctr_chart=0; while($ctr_chartitem($ctr_chart)->nodeValue; echo " ";

                                $ctr_chart++;
                            }
                            echo"
                                <input type='submit' value='Set Chart as Default' onClick='set_default_chart('chart$ctr',$ctr_module,$ctr_report)'/>
                            ";
                            echo "
                            <button class='btn btn-box-right' data-toggle='collapse' data-target='#container".$ctr."'>
                                <i class='icon-reorder'></i>
                            </button>
                        </div>
                        <div class='box-content box-list collapse in'>
                            <div id='container".$ctr."' style='min-width: 310px; height: 400px; margin: 0 auto'></div>
                        </div>
                    </div>
                </div>
            ";

            $ctr++;
            }
            $ctr_report++;
        }
        $ctr_module++;
    }
    echo "<label id='containers' value='$ctr'></label></div>";
}`

its kinda long but what it does is that it makes the containers ready and my java script is there to load and completely show the graphs. its in the document.ready function. it is possible that it prioritizes the codes that have function before loading the view?

1
It could be usefull to write your loadGraphs codeknizhnikov
o yeah. gonna edit my question.ssie_28

1 Answers

0
votes

You could try loading that results of the loadGraphs() function via AJAX from the view once it loads? So basically remove that call after the $this->load->view('EIM/home'), and in that same view, in documentReady, use the simple jQuery.Get function to fetch that code you need in the view. That will load if after the view 100%.

http://api.jquery.com/jquery.get/

Not sure if your flow is the best approach, but this should work.

Hope it helps! :)