webzop / yii2-notifications

Yii2 module to provide a notification managing system
BSD 3-Clause "New" or "Revised" License
69 stars 42 forks source link

Mark as read issue #23

Open generalmroaerosapace opened 2 years ago

generalmroaerosapace commented 2 years ago

I get an error when I try to mark as read any notification

mark as read issue

generalmroaerosapace commented 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();