Yii2 machour NotificationsWidget class 未找到
Yii2 machour NotificationsWidget class not found
我们正在尝试 运行 "machour" Yii2-Advanced 模板中的通知小部件。我们可以通过 composer 成功安装扩展。
我们收到以下 class 错误:
Class 'NotificationsWidget' 未找到。
以上问题依然存在Yii2 notification widget class not found。
我们在布局文件夹中调用以下代码:
use common\models\Notification;
<?php NotificationsWidget::widget([
'theme' => NotificationsWidget::THEME_GROWL,
'clientOptions' => [
'location' => 'br',
],
'counters' => [
'.notifications-header-count',
'.notifications-icon-count'
],
'markAllSeenSelector' => '#notification-seen-all',
'listSelector' => '#notifications',
]);
?>
这是文件夹中的代码:common/models:
<?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\db\Expression;
use machour\yii2\notifications\models\Notification as BaseNotification;
class Notification extends BaseNotification
{
/**
* A new message notification
*/
const KEY_NEW_MESSAGE = 'new_message';
/**
* A meeting reminder notification
*/
const KEY_MEETING_REMINDER = 'meeting_reminder';
/**
* No disk space left !
*/
const KEY_NO_DISK_SPACE = 'no_disk_space';
/**
* @var array Holds all usable notifications
*/
public static $keys = [
self::KEY_NEW_MESSAGE,
self::KEY_MEETING_REMINDER,
self::KEY_NO_DISK_SPACE,
];
/**
* @inheritdoc
*/
public function getTitle()
{
switch ($this->key) {
case self::KEY_MEETING_REMINDER:
return Yii::t('app', 'Meeting reminder');
case self::KEY_NEW_MESSAGE:
return Yii::t('app', 'You got a new message');
case self::KEY_NO_DISK_SPACE:
return Yii::t('app', 'No disk space left');
}
}
/**
* @inheritdoc
*/
public function getDescription()
{
switch ($this->key) {
case self::KEY_NO_DISK_SPACE:
// We don't have a key_id here
return 'Please buy more space immediately';
}
}
/**
* @inheritdoc
*/
public function getRoute()
{
switch ($this->key) {
case self::KEY_NO_DISK_SPACE:
return 'https://aws.amazon.com/';
};
}
}
和里面的配置代码frontend/config:
'modules' => [
'redactor' => 'yii\redactor\RedactorModule',
'notifications' => [
'class' => 'machour\yii2\notifications\NotificationsModule',
// Point this to your own Notification class
// See the "Declaring your notifications" section below
'notificationClass' => 'common\models\Notification',
// Allow to have notification with same (user_id, key, key_id)
// Default to FALSE
'allowDuplicate' => false,
// Allow custom date formatting in database
'dbDateFormat' => 'Y-m-d H:i:s',
// This callable should return your logged in user Id
'userId' => function() {
return \Yii::$app->user->id;
}
],
],
添加NotificationsWidget
class 文件路径如
use machour\yii2\notifications\widgets\NotificationsWidget;
use common\models\Notification;
<?php NotificationsWidget::widget([
'theme' => NotificationsWidget::THEME_GROWL,
'clientOptions' => [
'location' => 'br',
],
'counters' => [
'.notifications-header-count',
'.notifications-icon-count'
],
'markAllSeenSelector' => '#notification-seen-all',
'listSelector' => '#notifications',
]);
?>
我们正在尝试 运行 "machour" Yii2-Advanced 模板中的通知小部件。我们可以通过 composer 成功安装扩展。
我们收到以下 class 错误: Class 'NotificationsWidget' 未找到。
以上问题依然存在Yii2 notification widget class not found。
我们在布局文件夹中调用以下代码:
use common\models\Notification;
<?php NotificationsWidget::widget([
'theme' => NotificationsWidget::THEME_GROWL,
'clientOptions' => [
'location' => 'br',
],
'counters' => [
'.notifications-header-count',
'.notifications-icon-count'
],
'markAllSeenSelector' => '#notification-seen-all',
'listSelector' => '#notifications',
]);
?>
这是文件夹中的代码:common/models:
<?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\db\Expression;
use machour\yii2\notifications\models\Notification as BaseNotification;
class Notification extends BaseNotification
{
/**
* A new message notification
*/
const KEY_NEW_MESSAGE = 'new_message';
/**
* A meeting reminder notification
*/
const KEY_MEETING_REMINDER = 'meeting_reminder';
/**
* No disk space left !
*/
const KEY_NO_DISK_SPACE = 'no_disk_space';
/**
* @var array Holds all usable notifications
*/
public static $keys = [
self::KEY_NEW_MESSAGE,
self::KEY_MEETING_REMINDER,
self::KEY_NO_DISK_SPACE,
];
/**
* @inheritdoc
*/
public function getTitle()
{
switch ($this->key) {
case self::KEY_MEETING_REMINDER:
return Yii::t('app', 'Meeting reminder');
case self::KEY_NEW_MESSAGE:
return Yii::t('app', 'You got a new message');
case self::KEY_NO_DISK_SPACE:
return Yii::t('app', 'No disk space left');
}
}
/**
* @inheritdoc
*/
public function getDescription()
{
switch ($this->key) {
case self::KEY_NO_DISK_SPACE:
// We don't have a key_id here
return 'Please buy more space immediately';
}
}
/**
* @inheritdoc
*/
public function getRoute()
{
switch ($this->key) {
case self::KEY_NO_DISK_SPACE:
return 'https://aws.amazon.com/';
};
}
}
和里面的配置代码frontend/config:
'modules' => [
'redactor' => 'yii\redactor\RedactorModule',
'notifications' => [
'class' => 'machour\yii2\notifications\NotificationsModule',
// Point this to your own Notification class
// See the "Declaring your notifications" section below
'notificationClass' => 'common\models\Notification',
// Allow to have notification with same (user_id, key, key_id)
// Default to FALSE
'allowDuplicate' => false,
// Allow custom date formatting in database
'dbDateFormat' => 'Y-m-d H:i:s',
// This callable should return your logged in user Id
'userId' => function() {
return \Yii::$app->user->id;
}
],
],
添加NotificationsWidget
class 文件路径如
use machour\yii2\notifications\widgets\NotificationsWidget;
use common\models\Notification;
<?php NotificationsWidget::widget([
'theme' => NotificationsWidget::THEME_GROWL,
'clientOptions' => [
'location' => 'br',
],
'counters' => [
'.notifications-header-count',
'.notifications-icon-count'
],
'markAllSeenSelector' => '#notification-seen-all',
'listSelector' => '#notifications',
]);
?>