Итак, у меня есть одна первичная таблица comment
, которая имеет несколько полей. Затем Я хочу вставить некоторые поля в таблицу notifications
всякий раз, когда новая запись будет вставлена в таблицу comment
.Контроллер не может вставить в таблицу уведомлений в yii
В контроллере изначально я имел это, и она работала для comment
стола:
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,
));
}
Тогда я положил еще несколько строк для notification
таблицы. Но это не сработало.
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,
));
}
Функция для comment
стол все еще работает. Но для таблицы notifications
нет. Я попытался переставить позиции, но ничего не произошло. Я также изменил $notif->save();
на $notif->insert();
, но все равно ничего не произошло. Что я пропустил?
Это структура таблицы:
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 ;
Напишите таблицу с базой данных – Hearaman
Хорошо, я обновил свой вопрос. – Safira