What I want to do is that when the admin updates table A, the former record would be saved on table B.
For example:
* before updating table A*
[TableA] 1234, "new medicine trials", "<p>There is an increased [...]</p>", "2010-01-10"
* after updating table A*
[TableA] 1234, "New Medical Trials are underway", "<p>There is an increased [....]</p>", "2011-05-17"
[TableB] 1, 1234, "new medicine trials", "<p>There is an increased [...]</p>", "2010-01-10"
I am new to yii as well so I can’t be 100% of help but I can point you to the right direction.
Any model that inherits the class CActiveRecord has a method called beforeSave() that is called before a table is being updated.
Having said that, on Table A model
you would implement the beforeSave() method:
protected function beforeSave()
{
$tableB = new TableB();
//my guess is that the Table B id is auto_increment
$tableB->tblAid = $this->id;
$tableB->title = $this->title;
$tableB->body = $this->body;
$tableB->lastupdated = $this->lastupdated;
$tableB->save();
}
Then the update function should do the rest for TableA
Again not 100% sure this will work but I think it should. You can also getAttributes() and setAttributes() on a CActiveRecord class but I don’t know how that would work with two id’s. Perhaps somebody else could help you with that. I hope it works and it was useful.