在 codeigniter 错误时更新行
update rows on codeigniter error
我正在制作这个编辑功能,它没有编辑任何东西。我对这件事很陌生。我得到了我正在编辑的值,但我无法更新或保存它。如果它无法更新数据库,我也会将其重定向到编辑视图,但我收到此错误,`消息:尝试获取 属性 of non-object
文件名:views/edit_view.php
行号:15`
这是代码。
控制器
/// 编辑
public function update(){
$data['content'] = $this->Provinces_Model->getrow();
$data['content_view'] = 'Provinces/edit_view';
$this->templates->admin_template($data);
}
public function update_row(){
if($this->Provinces_Model->update()){
redirect('Provinces/index');
}else{
$this->update();
}
}
型号
//// 编辑
public function getrow(){
$this->db->where('PROV_ID', $this->uri->segment(3));
$query = $this->db->get($this->table);
return $query->row();
}
public function update(){
$id = $this->input->post('PROV_ID');
$input = array(
'PROVINCE' => $this->input->post('PROVINCE')
);
$this->db->where('PROV_ID', $this->uri->segment(3));
$update = $this->db->update($this->table, $input);
}
阅读视图
<td><?php echo anchor("Provinces/update/$i->PROV_ID","<i class='fa fa-edit'>" ); ?></td>
edit view
<div>
<center>
<fieldset>
<?php
echo form_open('Provinces/update_row');
?>
<p>
<label class="field" for="PROVINCE"><span>*</span>Province Name:</label>
<input type = "text" name="PROVINCE" class ="textbox-300" value= "<?php echo $content->PROVINCE; ?>">
<label class = "error"><?php echo form_error("PROVINCE"); ?></label>
</p>
<?php
echo form_submit('submit','Update');
echo form_close();
?>
</fieldset>
</center>
</div>
当我调用 update_row() 时,我的 url 变为 localhost/foldername/classname/update_row 所以如您所见,$this->uri->segment(3)
变为空。我所做的是编辑 edit_view..
<?php
$data = $content->PROV_ID;
echo form_open('Provinces/update_row/'.$data);
?>
我把 .$data 放在最后,这样 url 就会变成 localhost/foldername/classname/update_row/valueof$data
我正在制作这个编辑功能,它没有编辑任何东西。我对这件事很陌生。我得到了我正在编辑的值,但我无法更新或保存它。如果它无法更新数据库,我也会将其重定向到编辑视图,但我收到此错误,`消息:尝试获取 属性 of non-object
文件名:views/edit_view.php
行号:15`
这是代码。
控制器
/// 编辑
public function update(){
$data['content'] = $this->Provinces_Model->getrow();
$data['content_view'] = 'Provinces/edit_view';
$this->templates->admin_template($data);
}
public function update_row(){
if($this->Provinces_Model->update()){
redirect('Provinces/index');
}else{
$this->update();
}
}
型号
//// 编辑
public function getrow(){
$this->db->where('PROV_ID', $this->uri->segment(3));
$query = $this->db->get($this->table);
return $query->row();
}
public function update(){
$id = $this->input->post('PROV_ID');
$input = array(
'PROVINCE' => $this->input->post('PROVINCE')
);
$this->db->where('PROV_ID', $this->uri->segment(3));
$update = $this->db->update($this->table, $input);
}
阅读视图
<td><?php echo anchor("Provinces/update/$i->PROV_ID","<i class='fa fa-edit'>" ); ?></td>
edit view
<div>
<center>
<fieldset>
<?php
echo form_open('Provinces/update_row');
?>
<p>
<label class="field" for="PROVINCE"><span>*</span>Province Name:</label>
<input type = "text" name="PROVINCE" class ="textbox-300" value= "<?php echo $content->PROVINCE; ?>">
<label class = "error"><?php echo form_error("PROVINCE"); ?></label>
</p>
<?php
echo form_submit('submit','Update');
echo form_close();
?>
</fieldset>
</center>
</div>
当我调用 update_row() 时,我的 url 变为 localhost/foldername/classname/update_row 所以如您所见,$this->uri->segment(3)
变为空。我所做的是编辑 edit_view..
<?php
$data = $content->PROV_ID;
echo form_open('Provinces/update_row/'.$data);
?>
我把 .$data 放在最后,这样 url 就会变成 localhost/foldername/classname/update_row/valueof$data