PHPackages                             cvo-technologies/cakephp-notifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. cvo-technologies/cakephp-notifier

ActiveCakephp-plugin[Mail &amp; Notifications](/categories/mail)

cvo-technologies/cakephp-notifier
=================================

CvoTechnologies/Notifier plugin for CakePHP

1.0.0(9y ago)11291MITPHPPHP &gt;=5.4.16

Since Aug 8Pushed 9y agoCompare

[ Source](https://github.com/CVO-Technologies/cakephp-notifier)[ Packagist](https://packagist.org/packages/cvo-technologies/cakephp-notifier)[ RSS](/packages/cvo-technologies-cakephp-notifier/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

CvoTechnologies/Notifier plugin for CakePHP
===========================================

[](#cvotechnologiesnotifier-plugin-for-cakephp)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/694e5ffacaf02a1212a9bf3b23b25984391670af5391778681f409d476a443a3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f43564f2d546563686e6f6c6f676965732f63616b657068702d6e6f7469666965722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/CVO-Technologies/cakephp-notifier)[![Coverage Status](https://camo.githubusercontent.com/5f7a915d6ec2415cd1eb6178e09e4bbfef474c80f4525e89a392d39ae20a4180/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f63766f2d746563686e6f6c6f676965732f63616b657068702d6e6f7469666965722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/cvo-technologies/cakephp-notifier)[![Total Downloads](https://camo.githubusercontent.com/3257a0a2e697a416e48574250bee6d5abe4518a3b4e1bd2eafe55ad4ebce0f6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63766f2d746563686e6f6c6f676965732f63616b657068702d6e6f7469666965722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cvo-technologies/cakephp-notifier)[![Latest Stable Version](https://camo.githubusercontent.com/5645e74cb49c48ab70010e8457c0d4adea8cae831d975d7de853a82807c414ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63766f2d746563686e6f6c6f676965732f63616b657068702d6e6f7469666965722e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/cvo-technologies/cakephp-notifier)

Usage
-----

[](#usage)

### Configuring notifications transports

[](#configuring-notifications-transports)

Add the following section to your application config in `app.php`.

```
    'NotificationTransport' => [
        'email' => [
            'className' => 'CvoTechnologies/Notifier.Email',
            'profile' => 'default',
        ],
        'irc' => [
            'className' => 'Irc',
            'channel' => '#cvo-technlogies'
        ],
        'twitter' => [
            'className' => 'CvoTechnologies/Twitter.Twitter',
        ],
        'example' => [
            'className' => 'Example',
            'someOption' => true
        ]
    ],
```

### Creating a notifier

[](#creating-a-notifier)

```
namespace App\Notifier;

use CvoTechnologies\Notifier\Notifier;

class UserNotifier extends Notifier
{
    public function welcome($user)
    {
        $this
            ->to([
                'irc' => $user->irc_nickname,
                'twitter' => $user->twitter_nickname
            ])
            ->subject(sprintf('Welcome %s', $user->name))
            ->template('welcome_message') // By default template with same name as method name is used.
            ->viewVars([
                'user' => $user
            ])
            ->transports([
                'irc',
                'twitter'
            ]);
    }
}
```

#### Creating notification template

[](#creating-notification-template)

Create a template file in `Template/Notification/transport-type`. This will be used as template for the notification.

For example: `Template/Notification/irc/welcome.ctp`

```
Welcome  to our website!
```

#### Using it

[](#using-it)

Using the notifier is very easy. Here's an example on how to use it in a controller:

```
namespace App\Controller;

use CvoTechnologies\Notifier\NotifierAwareTrait;

class UsersController extends AppController
{
    use NotifierAwareTrait;

    public function register()
    {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data())
            if ($this->Users->save($user)) {
                $this->getNotifier('User')->send('welcome', [$user]);
            }
        }
        $this->set('user', $user);
    }
}
```

### Creating a transport

[](#creating-a-transport)

A transport is used to talk to a particular service.

It can accept configuration options that are passed from the `NotificationTransport` section in your application config.

```
