Open generalmroaerosapace opened 2 years ago
//------------------AccountNotification---------------------
namespace app\notifications;
use Yii; use webzop\notifications\Notification;
class AccountNotification extends Notification { const KEY_NEW_ACCOUNT = 'new_account';
const KEY_RESET_PASSWORD = 'reset_password';
const KEY_NEW_MESSAGE = 'new_message';
/**
* @var \yii\web\User the user object
*/
public $user;
public $message;
/**
* @inheritdoc
*/
public function getTitle(){
switch($this->key){
case self::KEY_NEW_ACCOUNT:
return Yii::t('app', 'New account {user} created', ['user' => '#'.$this->user->id]);
case self::KEY_RESET_PASSWORD:
return Yii::t('app', 'Instructions to reset the password');
case self::KEY_NEW_MESSAGE:
return Yii::t('app', '{message}', ['message' => $this->message]);
}
}
}
//------------Create a notification message---------------------
$user = User::findOne(['id' => $id]); $notification = AccountNotification::create(AccountNotification::KEY_NEW_MESSAGE, ['user' => $user, 'message' => $model->message]); $notification->setUserId($id); $notification->send();
I get an error when I try to mark as read any notification