<?php $baseurl = Yii::app()->request->baseUrl; $notfurl = $this->createUrl('/notificacao/render', array('id' => Yii::app()->user->getId())); Yii::app()->clientScript->registerScript('notif', "\n var template = '{$baseurl}';\n var notf = new EJS({url: '{$baseurl}/js/templates/_notificacoes.ejs'});\n \n setInterval(function(){\n \$.get('{$notfurl}',{json: true} ,function(data){ \n \$('#notificacoes').html(notf.render(data));\n }, 'json');\n }, 15000); \n"); if (!isset($notificacoes)) { $notificacoes = Notificacao::getNotifications(Yii::app()->user->getId()); } ?> <li class="dropdown" id="notificacoes"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Notificações <?php if ($notificacoes['count_new'] > 0) { ?> <span class="badge badge-warning"><?php echo $notificacoes['count_new']; ?> </span><b class="caret"></b> <?php } ?> </a> <ul class="dropdown-menu"> <?php foreach ($notificacoes['items'] as $ntf) { ?> <li class="ntf <?php echo $ntf['read'] == true ? '' : 'notif-new'; ?>
public function actionIndex() { $user = Yii::app()->user->getId(); $model = Pessoa::model()->findByPk($user); if ($model === null) { throw new CHttpException(404); } $this->render('index', array('model' => $model, 'notificacoes' => Notificacao::getNotifications($user, 10))); }