参数fore

时间:2016-02-09 02:35:34

标签: codeigniter

查看代码

<?php foreach($payment as $test){?>
 <tr>
     <td><?php echo $test->customerName;?></td>
     <td><?php echo $test->dateTime;?></td>
     <td><?php echo $test->amount;?></td>
  </tr>    
 <?php }?>  

控制器代码

function __construct() {
    parent::__construct();
    $this->load->database();
    $this->load->model('Income_sales_model');
}

public function index()
{
    $this->data['pja_test'] = $this->Income_sales_model->get_all();
    $this->load->view('income_sales_view', $data);
}

**这里是我的错误**

I'm stuck here I don't know what to do..

2 个答案:

答案 0 :(得分:1)

您尝试访问的变量必须是$data的密钥... 因此,在您的视图中print_r($pja_test);die;您将获得适当的输出 如果还有任何问题,请告诉我

答案 1 :(得分:0)

控制器代码

function __construct() {
    parent::__construct();
    $this->load->database();
    $this->load->model('Income_sales_model');
}

public function index()
{
    $data['payment'] = $this->Income_sales_model->get_all();  // $query->result();
    $this->load->view('income_sales_view', $data);
}