首页 > 解决方案 > 发送 codeIgniter result_array 以在视图中访问

问题描述

当我加载 codeIgniter 文件时,我使用 print_r 获得的结果不会发送到视图文件。请帮忙?

模型

class Tether extends CI_Model {
public $table='';
public $primary_key='';

    public function fetch_data(){
    $this->db->select('*');
    $this->db->from($this->table);
    $this->db->order_by($this->primary_key,'desc');
    return $this->db->get()->result_array();        
   }

控制器

    public function index(){    
    $task=new Tether;
    $task->table=$this->table;
    $query=$task->fetch_data();
    print_r($query);
    $this->load->view('layout_chart',$query);

print_r 结果是:

Array ( [0] => Array ( [trend_id] => 1 [month] => JANUARY [year] => 2015 [amount] => 10000 ) [1] => Array ( [trend_id] => 2 [month] => FEBRUARY [year] => 2015 [amount] => 15000) [2] => 数组 ([trend_id] => 3 [month] => MARCH [year] => 2015 [amount] => 20000)

标签: phpcodeigniter

解决方案


控制器:

$query['result'] = $task->fetch_data();

在 layout_chart 视图中:

print_r($result);

推荐阅读