PHP code example of reliefapps / notification-bundle
1. Go to this page and download the library: Download reliefapps/notification-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
reliefapps / notification-bundle example snippets
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Reliefapps\NotificationBundle\ReliefappsNotificationBundle(),
);
// ...
}
// ...
}
// ...
class YourController
{
// ...
public function YourAction()
{
// ...
// Get the Device Manager
$deviceManager = $this->get('reliefapps_notification.device.manager');
// Create a new device
$newDevice = $deviceManager->createDevice($uuid, $platform);
$newDevice->setToken($token);
// Save the device in database
$deviceManager->udpateDevice($newDevice);
}
}
use Reliefapps\NotificationBundle\Resources\Model\NotificationBody;
// ...
class YourController
{
// ...
public function YourAction()
{
// ...
$body = new NotificationBody();
$body ->setTitle('Notification Title') // Title of the notification
->setBody('This is a notification !') // Text of the notification
->setBadge(42); // Badge on the app icon (iOS only)
}
}
// ...
class YourController
{
// ...
public function YourAction()
{
// ...
// Get the Push Manager
$pushManager = $this->container->get('reliefapps_notification.push_manager');
// Send a push notification to devices $device1 and $device2
$pushManager->sendPush(Array($device1, $device2), $body);
}
}
// ...
class YourController
{
// ...
public function YourAction()
{
// ...
// The third parameter ("default" by default) indicates the context
$pushManager->sendPush(Array($device1, $device2), $body, 'ctx_app2');
}
}