在 Yii 中创建修订历史
Creating a Revision History in Yii
我正在使用 Yii。我目前已经设置好了,所以我可以覆盖属于 bug_id 的数据。但我想将此数据保存到 history_id 下的另一个模型(历史记录),一旦你编辑错误,它不会更改保存在历史记录 table 中的数据。
我用于更新错误数据的代码是:
public function actionUpdateBug($id)
{
$model=$this->loadModel($id);
$model->created_date= date('Y-m-d G:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Bugs']))
{
$model->attributes=$_POST['Bugs'];
if($model->save())
$this->redirect(array('id'=>$model->bug_id));
}
$this->render('update',array(
'model'=>$model,
));
}
表格如下:
错误
bug_id - Primary Key,
bug_title,
img,
description,
project_id - Foreign Key,
created_date
历史
history_id - Primary Key,
bug_id - Foreign Key,
bug_title,
img,
description,
created_date
任何帮助将不胜感激,谢谢
试试这个,
// Save to History table
$history = new History;
$history->attributes=$model->attributes;
$history->save();
你的更新函数,
public function actionUpdateBug($id)
{
$model=$this->loadModel($id);
$model->created_date= date('Y-m-d G:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Bugs']))
{
$model->attributes=$_POST['Bugs'];
if($model->save()){
// Save to History table
$history = new History;
$history->attributes=$model->attributes;
$history->save();
$this->redirect(array('id'=>$model->bug_id));
}
}
$this->render('update',array(
'model'=>$model,
));
}
我正在使用 Yii。我目前已经设置好了,所以我可以覆盖属于 bug_id 的数据。但我想将此数据保存到 history_id 下的另一个模型(历史记录),一旦你编辑错误,它不会更改保存在历史记录 table 中的数据。
我用于更新错误数据的代码是:
public function actionUpdateBug($id)
{
$model=$this->loadModel($id);
$model->created_date= date('Y-m-d G:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Bugs']))
{
$model->attributes=$_POST['Bugs'];
if($model->save())
$this->redirect(array('id'=>$model->bug_id));
}
$this->render('update',array(
'model'=>$model,
));
}
表格如下:
错误
bug_id - Primary Key,
bug_title,
img,
description,
project_id - Foreign Key,
created_date
历史
history_id - Primary Key,
bug_id - Foreign Key,
bug_title,
img,
description,
created_date
任何帮助将不胜感激,谢谢
试试这个,
// Save to History table
$history = new History;
$history->attributes=$model->attributes;
$history->save();
你的更新函数,
public function actionUpdateBug($id)
{
$model=$this->loadModel($id);
$model->created_date= date('Y-m-d G:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Bugs']))
{
$model->attributes=$_POST['Bugs'];
if($model->save()){
// Save to History table
$history = new History;
$history->attributes=$model->attributes;
$history->save();
$this->redirect(array('id'=>$model->bug_id));
}
}
$this->render('update',array(
'model'=>$model,
));
}