_flash.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2017-03-15 21:16
  7. */
  8. if (Yii::$app->getSession()->hasFlash('success')) {
  9. $successTitle = addslashes( Yii::t('app', 'Success') );
  10. $info = addslashes( Yii::$app->getSession()->getFlash('success') );
  11. $str = <<<EOF
  12. toastr.options = {
  13. "closeButton": true,
  14. "debug": false,
  15. "progressBar": true,
  16. "positionClass": "toast-top-center",
  17. "showDuration": "400",
  18. "hideDuration": "1000",
  19. "timeOut": "1000",
  20. "extendedTimeOut": "1000",
  21. "showEasing": "swing",
  22. "hideEasing": "linear",
  23. "showMethod": "fadeIn",
  24. "hideMethod": "fadeOut"
  25. };
  26. toastr.success("{$successTitle}", "{$info}");
  27. EOF;
  28. $this->registerJs($str);
  29. }
  30. if (Yii::$app->getSession()->hasFlash('error')) {
  31. $errorTitle = addslashes( Yii::t('app', 'Error') );
  32. $info = addslashes( Yii::$app->getSession()->getFlash('error') );
  33. $str = <<<EOF
  34. toastr.options = {
  35. "closeButton": true,
  36. "debug": false,
  37. "progressBar": true,
  38. "positionClass": "toast-top-center",
  39. "showDuration": "400",
  40. "hideDuration": "1000",
  41. "timeOut": "1000",
  42. "extendedTimeOut": "1000",
  43. "showEasing": "swing",
  44. "hideEasing": "linear",
  45. "showMethod": "fadeIn",
  46. "hideMethod": "fadeOut"
  47. };
  48. toastr.error("{$errorTitle}", "{$info}");
  49. EOF;
  50. $this->registerJs($str);
  51. }
  52. ?>