在我看来,我有以下代码:
if (($news['newsvideo'] !="") || ($news['newsvideo'] != NULL)) {
$newdata4 = array(
'tablename' => 'news',
'recordid' => $news['newsid'],
'fieldname' => 'newsid',
'fieldToUpdate' => 'newsvideo',
'dpage' => 'news/editNews'
);
$this->session->set_userdata($newdata4);
echo anchor('news/updateOneField', 'Delete Video?','class=btn');
}
if (($news['newsvideo_en'] !="") || ($news['newsvideo_en'] != NULL)) {
$newdata5 = array(
'tablename' => 'news',
'recordid' => $news['newsid'],
'fieldname' => 'newsid',
'fieldToUpdate' => 'newsvideo_en',
'dpage' => 'news/editNews'
);
$this->session->set_userdata($newdata5);
echo anchor('news/updateOneField', 'Delete Video?','class=btn');
}
我的控制器中的功能如下:
public function updateOneField()
{
$tablename = $this->session->userdata('tablename');
$id = $this->session->userdata('recordid');
$fieldname = $this->session->userdata('fieldname');
$fieldToUpdate = $this->session->userdata('fieldToUpdate');
//$this->newsModel->save(array($fieldToUpdate => ''), $id);
//$newsid = $id;
echo "Table name: ". $tablename . "<br/>";
echo "Id: " . $id. "<br/>";
echo "Field name: " . $fieldname. "<br/>";
echo "Field to update: " . $fieldToUpdate. "<br/>";
die();
// destroy the session after the update
$this->session->unset_userdata('tablename');
$this->session->unset_userdata('recordid');
$this->session->unset_userdata('fieldname');
$this->session->unset_userdata('fieldToUpdate');
$this->displayEditNewsForm($newsid);
}
现在,如果我点击我想删除新闻视频的第一个链接,当尝试更新 newsvideo 字段时,newsvideo_en 会更新。这意味着我稍后会覆盖数组的值。有谁知道如何避免这种情况并更新正确的字段?
问候,佐兰