在另一个函数中使用来自函数的数据笨

时间:2016-10-03 19:59:16

标签: php codeigniter

我有来自Api Post调用的数组,存储到$valores上的getApi(),我只需要从我的视图中访问该数组以显示数据

public function getApi(){
  $valores = $this->input->post('data');
  // print_r($valores); <--- with this i see the array in my console.log
    return $valores;
}

public function index()
    {

    // includes
    $data['footer'] = $this->load->view('includes/footer', NULL, TRUE);
    $dashboard['api'] = $this->getApi(); <-- i want to render this on my view

    // Menu

    $data['menuProfile'] = $this->load->view('app/menuProfile', NULL, TRUE);
    $data['sidebarMenu'] = $this->load->view('app/sidebarMenu', NULL, TRUE);
    $data['topNavigation'] = $this->load->view('app/topNavigation', NULL, TRUE);
    $data['menuFooter'] = $this->load->view('app/menuFooter', NULL, TRUE);

    // Dashboard

    $dashboard['dinp'] = $this->load->view('app/dashboard/dinp', NULL, TRUE);
    $dashboard['dispTitle'] = $this->load->view('app/dashboard/dispTitle', NULL, TRUE);
    $dashboard['porcentaje'] = $this->load->view('app/dashboard/porcentaje', NULL, TRUE);
    $dashboard['temp'] = $this->load->view('app/dashboard/temp', NULL, TRUE);
    $dashboard['velocity'] = $this->load->view('app/dashboard/velocity', NULL, TRUE);
    $data['dashboard'] = $this->load->view('app/dashboard/dashboard', $dashboard, TRUE);


    $this->load->view('includes/head');
    $this->load->view('dashboard', $data);
    $this->load->view('includes/jquery');
    }

这就是我认为我可以在我的视图中显示数据的方式

<div class="right_col" role="main" id="Dashboard">
  <div class="">
    <div class="clearfix"></div>
      <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
          <div class="x_panel">
            <?=$dispTitle?>
            <div class="x_content">
            <div class="col-md-3 col-xs-12 widget widget_tally_box">
              <?=$api?>            <--- just doesn't display anything, i think its empty or null
              <!-- percent -->
              <?=$porcentaje?>
              <!-- dinp -->
              <?=$dinp?>
              <!-- dinp -->
              <?=$dinp?>
              <!-- temp -->
              <?=$temp?>
            </div>
          </div>
        </div>
      </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:-1)

将$ data传递给视图页面,但是你在

中保存了api返回数据
$dashboard['api']

尝试将此更改为

$data['api']