_flash.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. use common\widgets\JsBlock;
  9. if (Yii::$app->getSession()->hasFlash('success')) {
  10. $successTitle = Yii::t('app', 'Success');
  11. $info = Yii::$app->getSession()->getFlash('success');
  12. $str = <<<EOF
  13. toastr.options = {
  14. "closeButton": true,
  15. "debug": true,
  16. "progressBar": true,
  17. "positionClass": "toast-top-center",
  18. "showDuration": "400",
  19. "hideDuration": "1000",
  20. "timeOut": "1000",
  21. "extendedTimeOut": "1000",
  22. "showEasing": "swing",
  23. "hideEasing": "linear",
  24. "showMethod": "fadeIn",
  25. "hideMethod": "fadeOut"
  26. };
  27. toastr.success("{$successTitle}", "{$info}");
  28. EOF;
  29. JsBlock::begin();
  30. echo $str;
  31. JsBlock::end();
  32. }
  33. if (Yii::$app->getSession()->hasFlash('error')) {
  34. $errorTitle = Yii::t('app', 'Error');
  35. $info = Yii::$app->getSession()->getFlash('error');
  36. $str = <<<EOF
  37. toastr.options = {
  38. "closeButton": true,
  39. "debug": true,
  40. "progressBar": true,
  41. "positionClass": "toast-top-center",
  42. "showDuration": "400",
  43. "hideDuration": "1000",
  44. "timeOut": "1000",
  45. "extendedTimeOut": "1000",
  46. "showEasing": "swing",
  47. "hideEasing": "linear",
  48. "showMethod": "fadeIn",
  49. "hideMethod": "fadeOut"
  50. };
  51. toastr.error("{$errorTitle}", "{$info}");
  52. EOF;
  53. JsBlock::begin();
  54. echo $str;
  55. JsBlock::end();
  56. }
  57. ?>