Closed Sh1n1x closed 9 years ago
Hey @Sh1n1x,
Can you post me your stack trace?
The bug sounds strange to me because the NotificationManager
class doesn't have that method, the component does have it...
Greetz
Bob
@Sh1n1x I don't think it's because of Cake 3.1 because the CakeAdmin Plugin runs well with the notification-plugin...
i have maybe bad configured your plugin, i don't no ^^.
i've add that in my controller :
use Notifier\Utility\NotificationManager; ...
public function initialize()
{
parent::initialize();
$this->Notifier = NotificationManager::instance();
}
public function add(){
$this->Notifier->addTemplate('add', [
'title' => 'New blog by :username',
'body' => ':username has posted a new blog named :name'
]);
$this->Notifier->notify([
'users' => ['3339be99-4f0f-4aff-963f-3f7470192338'],
'recipientLists' => ['administrators'],
'template' => 'newBlog',
'vars' => [
'username' => 'Bob Mulder',
'name' => 'My great new blogpost'
]
]);
debug($this->Notifier->countsNotifications('3339be99-4f0f-4aff-963f-3f7470192338'));
}
Sorry for my english.
Thank you !
Hi @Sh1n1x,
This is no bug because of 3.1.
As you see you are calling the countsNotifications
-method on $this->Notifier
.
$this->Notifier
is an instance of the NotificationManager
-class.
However, that manager doesn't have the method countsNotifications
, the component does!
So try this (in your controller):
public function initialize()
{
parent::initialize();
$this->loadComponent('Notifier.Notifier'); // this will load the component
}
This will allow you to create new notifications and count them.
However, there's a second thing. You are using addTemplate
in your add
-method as well. This should be configured in your config/bootstrap.php
. When a notification is shown to the user, the template is used, and values (stored in database) are pushed into the templates.
It's good to get some feedback. It makes me realize that I can make some improvements to the docs to make it more clear to new users of CakePHP.
Let me know if it works!
Yes, i'm noob with CakePHP (1 week), but I must be stupid but it not working xD.
in my bootstrap.php : i've added
use Notifier\Utility\NotificationManager;
Plugin::load('Notifier', ['bootstrap' => true, 'routes' => true, 'autoload' => true]);
$notificationManager = NotificationManager::instance();
$notificationManager->addTemplate('newBlog', [
'title' => 'New blog by :username',
'body' => ':username has posted a new blog named :name'
]);
And in ArticlesController.php
public function add(){
debug($this->Notifier->countsNotifications('3339be99-4f0f-4aff-963f-3f7470192338'));
}
it's true or i'm very stupid xD?
I think it should work, check it yourself ;)
^^ I have the same issue : Error: Call to undefined method Notifier\Controller\Component\NotifierComponent::countsNotifications() File /Users/shinix/Sites/ClansGamers/src/Controller/Admin/ArticlesController.php
Ah ah ! okay it's working fine ! i was stupid xD !
Thank you for your fast answer !
:+1: Good luck and have fun ;)
Hi ! Thank you for your plugin.
I would like use this plugin on CakePHP 3.1.x and i have this error when trying to get the number of notification : Error: Call to undefined method Notifier\Utility\NotificationManager::countsNotifications()
I think the NotifierComponent don't load with the plugin.
Thank you for your answer.
(i'm using CakeDC/Users for User system and user_id is not in INT but in CHAR(36))