如何将不同的$ results从控制器传递到codeigniter中的查看页面?

时间:2016-02-09 06:23:00

标签: arrays codeigniter

我在视图页面中显示了显示不同结果的条件。我想在视图页面中传递这六个不同的结果数组。我试过了。但它确实没有work.pls帮助。

控制器

$m1=date('F');
$y1=date('Y');
$result['credit']=$this->money_m->gettotcredit($uid,$m1,$y1);
$result['loan']=$this->money_m->gettotloan($uid,$m1,$y1);
$result['bank']=$this->money_m->gettotbank($uid,$m1,$y1);
$result['insurance']=$this->money_m->gettotinsurance($uid,$m1,$y1);
$result['mutualfund']=$this->money_m->gettotmutualfund($uid,$m1,$y1);
$result['fdbonds']=$this->money_m->gettotfdbonds($uid,$m1,$y1);
        $result['assestliab']=array_unique( $result['credit'],$result['loan'],$result['bank'],$result['insurance'],$result['mutualfund'],$result['fdbonds']);
    $this->load->view('mainpage2',$result);

I want to take each result 

        foreach($credit as $cr)
        {

        .......
        }
    etc

2 个答案:

答案 0 :(得分:1)

试试这个

  

当您从控制器向视图传递数据时,请使用$data。这是一种很好的做法。

在控制器中

$data['credit'] = # some function 
$data['loan'] = # another function

$this->load->view('mainpage2',$data);

在视图中

foreach ($credit as $value) {
    echo $value['creditVariable'];
}

foreach ($loan as $value) {
    echo $value['loanVariable'];
}

在您的情况下

$m1=date('F');
$y1=date('Y');

$result['credit']=$this->money_m->gettotcredit($uid,$m1,$y1);
$result['loan']=$this->money_m->gettotloan($uid,$m1,$y1);
$result['bank']=$this->money_m->gettotbank($uid,$m1,$y1);
$result['insurance']=$this->money_m->gettotinsurance($uid,$m1,$y1);
$result['mutualfund']=$this->money_m->gettotmutualfund($uid,$m1,$y1);
$result['fdbonds']=$this->money_m->gettotfdbonds($uid,$m1,$y1);
# remove this line $result['assestliab']=array_unique( $result['credit'],$result['loan'],$result['bank'],$result['insurance'],$result['mutualfund'],$result['fdbonds']);


$this->load->view('mainpage2',$result);

在视图中

foreach ($credit as $value) {
    echo $value['creditVariable'];
}

foreach ($loan as $value) {
    echo $value['loanVariable'];
}

答案 1 :(得分:0)

将控制器值传递给View文件的格式

控制器

$m1=date('F');
$y1=date('Y');
$result['credit']=$this->money_m->gettotcredit($uid,$m1,$y1);
$result['loan']=$this->money_m->gettotloan($uid,$m1,$y1);
$result['bank']=$this->money_m->gettotbank($uid,$m1,$y1);
$result['insurance']=$this->money_m->gettotinsurance($uid,$m1,$y1);
$result['mutualfund']=$this->money_m->gettotmutualfund($uid,$m1,$y1);
$result['fdbonds']=$this->money_m->gettotfdbonds($uid,$m1,$y1);
$this->load->view('mainpage2',$result);

查看

if(isset($credit)) {

foreach($credit as $result) {

......
......

}

}