我有一个表格,要求用户输入有关他或她的猫的某些信息,然后用户可以提交他的信息并将其传输到数据库。我希望将此信息回显到视图中,因此它将显示已在表格中提交的每只猫。我认为我正确地使用了 foreach,但表格中没有填充我想要的内容。
这是我的观点的代码:
<form action="/Anish/create" method="POST">
<div>
<label>Name</label><input type="text" name="name">
</div>
<div>
<label>Age</label><input type="text" name="age">
</div>
<div>
<label>Gender</label><input type="text" name="gender">
</div>
<div>
<label>Species</label><input type="text" name="species">
</div>
<div>
<label>Eye Color</label><input type="text" name="eye_color">
</div>
<div>
<label>Color</label><input type="text" name="color">
</div>
<div>
<label>Description</label><input type="text" name="description">
</div>
<div>
<label>marital status</label><input type="text" name="marital_status">
</div>
<br>
<button type="submit" class="btn btn-block btn-primary span1">Add cat</button>
</form>
<br/>
<br/>
<br/><br/>
<table border="1">
<tr>
<td>Name</td>
<td>Gender</td>
<td>Age</td>
<td>Species</td>
<td>Eye Color</td>
<td>Color</td>
<td>Description</td>
<td>Marital Status</td>
</tr>
<td>
<?php
foreach ($data as $cats){
echo ($cats);
}
?>
</td>
</table>
这是我的控制器代码:
class Anish extends Public_Controller
{
public function __construct()
{
parent::__construct();
// Load the required classes
$this->load->model('Anish_m');
// $this->lang->load('anish');
}
public function index()
{
$data=array(
'cats'=>$this->Anish_m->get(),
);
// var_dump($data);die;
$this->template
->set('data', $data)
->build('index', $data);
}
public function create() {
$Anish = array(
'name' => $this->input->post('name'),
'age' => $this->input->post('age'),
'gender' => $this->input->post('gender'),
'species' => $this->input->post('species'),
'eye_color' => $this->input->post('eye_color'),
'color' => $this->input->post('color'),
'description' => $this->input->post('description'),
'marital_status' => $this->input->post('marital_status')
);
$createCat=$this->Anish_m->create($Anish);
redirect('/Anish');
}
}
我很感激任何帮助。