eluhr/yii2-notification-module

A notification module for Yii2

Maintainers

👁 eluhr

Package info

github.com/eluhr/yii2-notification-module

Type:yii2-extension

pkg:composer/eluhr/yii2-notification-module

Statistics

Installs: 15 497

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

1.3.11 2026-02-02 09:54 UTC

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 4b1b01d96f54c3cdb1ea0c515f645977672f93ba

  • Elias Luhr <elias.luhr.woop@gmail.com>

README

composer require eluhr/yii2-notification-module

Configuration

use eluhr\notification\components\Notification as NotificationComponent;
use eluhr\notification\Module as NotificationModule;
...
'modules' => [
 'notification' => [
 'class' => NotificationModule::class,
 // Optional: Override the list of possible message recipients
 // 'possibleUsersCallback' => function() {
 // return \yii\helpers\ArrayHelper::map(
 // \Da\User\Model\User::find()->where(['blocked_at' => null])->all(),
 // 'id',
 // 'username'
 // );
 // },
 ],
 'translatemanager' => [
 'root' => [
 '@vendor/eluhr/yii2-notification-module/src'
 ]
 ]
],
'components' => [
 'notification' => [
 'class' => NotificationComponent::class,
 'mailer' => 'mailer', // OPTIONAL: Default -> mailer
 'fromEmail' => 'notifications@domain.com' // REQUIRED
 ]
],
'controllerMap' => [
 'migrate' => [
 'migrationPath' => [
 '@vendor/eluhr/yii2-notification-module/src/migrations',
 ]
 ]
]
...

Example

Inbox from the point of view of a user with all authorizations 👁 Example inbox

Write a message to individual users or entire user groups Search messages by subject, author or text
👁 Compse message
👁 Filtered inbox
Group users to create your own personal user groups Mark, read or delete messages
👁 User group
👁 User group

Worth knowing

Requires PHP version >= 7.*

Example usuage

ExampleModel extends ActiveRecord implements ModelChangeNotification {
 
 /**
 * @return array
 */
 public function behaviors()
 {
 $behaviors = parent::behaviors();
 $behaviors['notification'] = [
 'class' => ModelChangeNotification::class,
 'receiverIds' => [MessageUserGroup::MESSAGE_USER_GROUP_ID_PREFIX . '1']
 ];
 return $behaviors;
 }
 
 
 /**
 * @return string
 */
 public function subject()
 {
 return $this->isNewRecord ? 'New entry' : ('Updated entry #' . $this->id);
 }
 
 /**
 * @return string
 */
 public function text()
 {
 $text = Html::tag('pre', htmlentities(json_encode($this->attributes, JSON_PRETTY_PRINT)));
 $text .= Html::tag('p', Html::a('Direct link',['/widgets/crud/widget-template/view','id' => $this->id], true));
 return $text;
 }
 
}

More infos coming soon

Ideas

The following stuff will probably come in a future release

  • Draft messages for later use
  • Ability to remove messages
  • Mark messages from users with a label or something
  • Notification Widget (AdminLTE)
  • Delete (inbox) message in overview (three dots option edit)
  • Translation config