1

私のモデル関数は

    public function getUser()
{
    $this->db->select(array('customer_name','customer_address','phone_no','fax','email_id','contact_person_name','mobile_no'));     
    $this->db->from('add_customer');
    $this->db->where(array('status'=>1));
    $res = $this->db->get();
    if($res->num_rows() > 0)
    { 
        $rows = $res->result_array();
        return $rows;
    }else{
        return false;
    }
}

コントローラーの機能

public function search_customer()
{

    //$this->load->helper('url');
    $data['baseurl'] = base_url();
    $this->load->view('templates/header');
    $data['details'] = $this->Customer_model->getUser();
    $this->load->view('master/customer',$data);
} 

私のビューから抽出するデータはこのようなものです

     <?php for($i=0;$i<count($details);$i++){ ?>
  <tr>
    <td><?php echo ($i+1); ?></td>
    <td><?php echo $details[$i]['customer_name']; ?></td>
    <td><?php echo $details[$i]['customer_address']; ?></td>
    <td><?php echo $details[$i]['phone_no']; ?></td>
    <td><?php echo $details[$i]['email_id']; ?></td>
    <td><?php echo $details[$i]['contact_person_name']; ?></td>
    <?php }?>

これはこのようなエラーになります

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: details

Filename: master/Customer.php

Line Number: 69 

このエラーが発生する理由を誰か教えてください

4

3 に答える 3

0

モデル:

public function getUser()
{
    $this->db->select('customer_name','customer_address','phone_no',
            'fax','email_id','contact_person_name','mobile_no');     
    $this->db->from('add_customer');
    $this->db->where('status',1);
    return $this->db->get()->result();
}

コントローラ:

public function search_customer()
{
    $data['baseurl'] = base_url();
    //Load the view in variable as data, but do not render 
    //($header is accessible in 'master/customer' view)
    $data['header'] = $this->load->view('templates/header','',true);
    //Be sure to load Customer_model
    $data['details'] = $this->Customer_model->getUser();
    $this->load->view('master/customer',$data);
} 

意見:

<?php if(count($details)): ?>
   <?php foreach($details as $detail): ?>
   <tr>
       <td><?php echo $detail->customer_name; ?></td>
       <td><?php echo $detail->customer_address; ?></td>
       <td><?php echo $detail->phone_no; ?></td>
       <td><?php echo $detail->email_id; ?></td>
       <td><?php echo $detail->contact_person_name; ?></td>
   </tr>
   <?php endforeach; ?>
<?php endif; ?>
于 2013-04-04T12:21:43.283 に答える
-1

マスター/顧客$dataの代わりに使用してみてください。$details

于 2013-04-03T12:04:15.150 に答える