I'm trying to find a way to implement an email notification functionality whenever a record is updated in the kf_notifications
table. The email notification should be sent to the email address that corresponds to the user_id
in the nofications table withinin the new updated record. Email ID is stored in a different table named kf_users
Controller:
public function actionNotification()
{
$uid = Yii::$app->user->identity->id;
if(isset($_GET['new'])) {
//get new notifications
$html = Yii::$app->Kiduchi->show_notification($uid);
}
else{
//get all notifications
$html = Yii::$app->Kiduchi->show_notification($uid,'all');
}
//update is_viewed
$connection = \Yii::$app->db;
$command = $connection->createCommand("UPDATE kf_notifications SET is_viewed=1 where user_id='$uid'");
$command->execute();
return $this->render('notification', ['html' => $html]);
}
kf_notification (model):
class Notifications extends \yii\db\ActiveRecord
/**
* @inheritdoc
*/
public static function tableName()
{
return 'kf_notifications';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['visible_all', 'user_id', 'text', 'is_viewed'], 'required'],
[['user_id', 'is_viewed'], 'integer'],
[['text'], 'string'],
[['created_on'], 'safe'],
[['visible_all'], 'string', 'max' => 255],
];
}