0
다음은 제 코드입니다.CodeIgniter에서 db에서 데이터를 가져 오려고하는데 오류가 발생했습니다.
컨트롤러 기능
function index()
{
$data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->model('customers_model');
$data['rows'] = $this->customers_model->getAll();
$meta['page_title'] = 'Customers';
$data['page_title'] = 'Customers';
$this->load->view('../header', $meta);
$this->load->view('content', $data);
$this->load->view('../footer');
}
모델 기능
public function getAll()
{
$q = $this->db->get('customers');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
파일보기
<table cellpadding=0 cellspacing=10 width="100%">
<thead>
<tr>
<th>Name</th>
<th>Company</th>
<th>Phone</th>
<th>Email</th>
<th>Address</th>
<th>City</th>
<th>Code</th>
<th>State</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $row):?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->company; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->city; ?></td>
<td><?php echo $row->postal_code; ?></td>
<td><?php echo $row->state; ?></td>
<td><?php echo $row->country; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
나는 점점 오전 오류
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/content.php
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/content.php
저는 처음으로 CI를 사용하고 있는데 무엇이 잘못되었는지 전혀 모릅니다. 도와주세요.
도움 주셔서 대단히 감사드립니다 ... – Saleem