我是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();
请帮我解决 .
3 回答
这个 :
应该 :
您可以创建一个二维数组,其中位置$ data ['costumers']从get_all_costumers()接收数据,位置$ data ['cats']从get_all_categories接收数据,然后将$ data传递给您的视图 . 这将是:
只是提醒一下,在您看来,您将像$ cats或$ costumers一样访问它们 .
以下是传递多变量进行查看的解决方案
Controller
在视图中,我们将使用$ customers和$ categories