【问题标题】:How to Pass multiple data array to view Codeigniter如何传递多个数据数组来查看 Codeigniter
【发布时间】:2018-02-27 08:29:59
【问题描述】:

我是 Codeigniter 的新手,有两个小问题

1:如何传递两个表数据数组来查看?

$data['customers']=$this->customer_model->get_all_customers(); 
        //$products['product']=$this->customer_model->get_all_categories();
        //$this->load->view("customer_view",$data);
        $product['cats']=$this->customer_model->get_all_categories(); 

         $this->loadViews("customer_view", $this->global, $data, $product);

但我遇到了错误

2:我加入两个表以获得两个表数据,但我只获得一个表数据?

public function get_all_categories()
{

/*// Get Data from Two tables
$this->db->select('*');
$this->db->from('category');
$this->db->join('customers','customers.categoryID=category.categoryID','Inner');
$query=$this->db->get();

请帮我解决。

【问题讨论】:

  • 你遇到了什么错误?

标签: codeigniter-3


【解决方案1】:

这个:

$query=$this->db->get();

应该是:

$query=$this->db->get()->result_array();

【讨论】:

    【解决方案2】:

    这是将多变量传递给视图的解决方案

    控制器

    $data['customers']=$this->customer_model->get_all_customers(); 
    $data['cats']=$this->customer_model->get_all_categories(); 
    
    
    $data ['customers'] = $customers;
            $data ['cats'] = $categories;
        $this->loadViews("customer_view", $this->global,  $data);
    

    在视图中我们将使用 $customers 和 $categories

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2014-08-07
      相关资源
      最近更新 更多