我试图用“machour的”通知窗口部件Yii2通知部件类
但不知何故,我甚至不能称之为类:NotificationWidget在我的代码
它说,“未找到类“
我正在使用yii2-basic-template,该如何调用该类?
编辑:
我试图创建目录:后端/组件并试图
使用后端/组件/通知;
但我使用基本的模板,所以我不认为这是正确的
https://github.com/machour/yii2-notifications
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'language' => 'en',
'bootstrap' => ['languagepicker'],
'modules' => [
'notifications' => [
'class' => 'machour\yii2\notifications\NotificationsModule',
// Point this to your own Notification class
// See the "Declaring your notifications" section below
'notificationClass' => 'app\models\Notification',
// Allow to have notification with same (user_id, key, key_id)
// Default to FALSE
'allowDuplicate' => false,
// This callable should return your logged in user Id
'userId' => function() {
return \Yii::$app->user->id;
}
],
'redactor' => 'yii\redactor\RedactorModule',
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => '@webroot/uploads',
'uploadUrl' => '../web/uploads',
],
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'languagepicker' => [
'class' => 'lajax\languagepicker\Component',
'languages' => ['en-US', 'vi'] // List of available languages (icons only)
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'hhs9xband',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => '',
'username' => '',
'password' => '',
'port' => '587',
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
这是代码,当我把它称为:
use backend\components\Notification
<?= NotificationsWidget::widget([
'theme' => NotificationsWidget::THEME_GROWL,
'clientOptions' => [
'location' => 'br',
],
'counters' => [
'.notifications-header-count',
'.notifications-icon-count'
],
'listSelector' => '#notifications',
]);
?>
这是内部代码:backend/components:
namespace backend\components;
use Yii;
use common\models\Meeting;
use common\models\Message;
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_MEETING_REMINDER:
$meeting = Meeting::findOne($this->key_id);
return Yii::t('app', 'You are meeting with {customer}', [
'customer' => $meeting->customer->name
]);
case self::KEY_NEW_MESSAGE:
$message = Message::findOne($this->key_id);
return Yii::t('app', '{customer} sent you a message', [
'customer' => $meeting->customer->name
]);
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_MEETING_REMINDER:
return ['meeting', 'id' => $this->key_id];
case self::KEY_NEW_MESSAGE:
return ['message/read', 'id' => $this->key_id];
case self::KEY_NO_DISK_SPACE:
return 'https://aws.amazon.com/';
};
}
}
这些代码是高级模板,我想我需要改变的东西,使之适用于基本模板
更新你的问题,并添加您your_basic_app /配置/ WEB-PHP ..please – scaisEdge
@scaisEdge我更新配置/网页代码 –
@scaisEdge我更新了代码,这应该在Advance模板中工作。基本模板 –