So I have one primary table comment
that has a number of fields. Then
I want to insert some fields into a notifications
table whenever a new record is inserted into comment
table.
In the controller, initially I had this and it worked for comment
table:
public function actionCreate() {
$model = new Comment;
if (isset($_POST['Comment'])) {
$model->attributes = $_POST['Comment'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->comment_id));
}
$this->render('create', array(
'model' => $model,
));
}
Then I put some more lines for the notification
table. But it didn't work.
public function actionCreate() {
$model = new Comment;
$notif = new Notifications;
if (isset($_POST['Comment'])) {
$model->attributes = $_POST['Comment'];
$notif->peg = 'nofriani';
$notif->tanggal = new CDbExpression("NOW()");
$notif->notif = ' mengirimkan berita ';
$notif->isi = $_POST['Comment']['post_id'];
$notif->link = 'links';
$notif->save();
if ($model->save())
$this->redirect(array('view', 'id' => $model->comment_id));
}
$this->render('create', array(
'model' => $model,
));
}
The function for comment
table still works. But the one for notifications
table doesn't. I tried to rearrange the positions but nothing happened. I also changed the $notif->save();
into $notif->insert();
but still nothing happened. What have I missed?
This is the table structure:
CREATE TABLE IF NOT EXISTS notifications (
id_notif int(11) NOT NULL AUTO_INCREMENT,
tanggal date NOT NULL,
peg varchar(30) NOT NULL,
notif text NOT NULL,
isi varchar(30) NOT NULL,
link varchar(255) NOT NULL,
PRIMARY KEY (id_notif)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;