2

How do I notify user on dashboard(index.php) as soon as new records get created in database or any changes made in database

Iknow I need to query like

CREATE TRIGGER notifyMe

    ON table1
    AFTER INSERT, UPDATE, DELETE 
    AS
       EXEC msdb.dbo.sp_send_dbmail
            @profile_name = 'DB AutoMailer',
            @recipients = 'user@example.com',
            @body = 'The DB has changed',
            @subject = 'DB Change';
    GO

but dont know how to do it by using Yii2 Events

In controller:

  Yii::$app->session->setFlash('success', "Your message to display");

In view

<?php if (Yii::$app->session->hasFlash('success')): ?>
  <div class="alert alert-success alert-dismissable">
  <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
  <h4><i class="icon fa fa-check"></i>Saved!</h4>
  <?= Yii::$app->session->getFlash('success') ?>
  </div>
<?php endif; ?>
JKLM
  • 1,470
  • 3
  • 28
  • 66
  • I've explained `yii2 events` here: http://stackoverflow.com/questions/28575636/how-to-use-events-in-yii2/28586567#28586567. I think it'll help you to design the solution. – Ejaz Karim Apr 16 '16 at 15:13
  • nice!! any tips to build event listeners? – JKLM Apr 16 '16 at 15:15
  • Everything about events and event handlers are explained in detailed in the yii2 guide.Please refer this link http://www.yiiframework.com/doc-2.0/guide-concept-events.html – Kiran Muralee Apr 16 '16 at 22:17
  • i need, how will yii detect that database has been changed – JKLM Apr 16 '16 at 22:18
  • @Saurabh.If yii code has done changes to your db,then surely you can trigger events based on the change. – Kiran Muralee Apr 17 '16 at 03:10

0 Answers0