Giter Site home page Giter Site logo

cakephp-notification-plugin's Introduction

CakePHP Notification Plugin

CakePHP Notification Plugin provide an notification system

Installation

Download the plugin

cd app/Plugin
git clone git://github.com/aschelch/cakephp-notification-plugin.git Notification

Attach the Notifiable behavior to the user model

public User extends AppModel{
	$actsAs = array(
		'Notification.Notifiable' => array(
			'subjects' => array('User', 'Post', 'Comment')
		)
	);
}

Usage

Notify the user #1 that the user #2 posted a comment (#123) on user #1's post (#456)

$this->User->notify(1, 'post_comment', array('User'=>2,'Post'=>456,'Comment'=>123));

Create an element in Elements/Notification/post_comment.ctp

<a href="<?php echo $this->Html->url(array('controller'=>'post','action'=>'view',$data['Post']['id'])) ?>">
	<?php echo __("%s comment your post %s", '<strong>'.$data['User']['username'].'</strong>', '<strong>'.$data['Post']['title'].'</strong>'); ?><br/>
	<small><?php echo $this->Time->niceShort($data['Notification']['created']); ?></small>
</a>

In your layout, display the notifications

<ul class="nav pull-right">
	<?php $notifications = ClassRegistry::init('User')->getUnreadNotification(AuthComponent::user('id')); ?>
	<li class="dropdown">
		<a href="#" class="dropdown-toggle" data-toggle="dropdown">
			<?php echo __('Notifications') ?>
			<?php if (!empty($notifications)): ?>
				<span class="badge badge-success">
					<?php echo count($notifications); ?>
				</span>
			<?php endif ?>
		</a>
		<ul class="dropdown-menu">
			<?php foreach ($notifications as $notification): ?>
				<li><?php echo $this->Notification->display($notification); ?></li>
				<li class="divider"></li>
			<?php endforeach ?>
			<li class="text-center"><?= $this->Html->link(__('Display all'), '#'); ?></li>
		</ul>
	</li>
</ul>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.