我在视图页面上遇到错误我是codeigniter的新手,请帮帮我......
这个是在视图页面
foreach($this->m->gettable() as $row)
{
echo "<tr>
<td>$row->id</td>
<td>$row->studentname</td>
<td>$row->gender</td>
<td>$row->phone</td>
<td></td>
</tr>";
}
在模型页面
function gettable()
{
$query=$this->db->get('tblstudent');
return $query->result();
}
在控制器页面
public function _construct()
{
parent::_construct();
//call model
$this->load->model("StudentModel","m");
}
function index()
{
$this->load->view("index");
}
function savedata()
{
//create array for get data from index
$data=array(
'studentname' => $this->input->post('studentname'),
'gender' => $this->input->post('gender'),
'phone' => $this->input->post('phone')
);
//mean that insert into database table name tblstudent
$this->db->insert('tblstudent',$data);
//mean that when insert already it will go to page index
redirect("Student/index");
}
答案 0 :(得分:0)
语法为__construct
,下划线为2x,而不是1x _construct
对其所有实例进行更改并使用错误报告:
答案 1 :(得分:0)
更改您的控制器索引功能,如下所示
function index()
{
$data['result']=$this->m->gettable();
$this->load->view("index",$data);
}
在视图页面上将其更改为以下内容。
foreach($result as $row)
{
echo "<tr>
<td>$row->id</td>
<td>$row->studentname</td>
<td>$row->gender</td>
<td>$row->phone</td>
<td></td>
</tr>";
}
这将有效。