BaseController.php 581 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace backend\controllers;
  3. use components\Exception;
  4. use yii\web\Controller;
  5. /**
  6. * Class BaseController
  7. * @package backend\controllers
  8. */
  9. class BaseController extends Controller
  10. {
  11. /**
  12. * init
  13. */
  14. public function init()
  15. {
  16. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  17. parent::init();
  18. }
  19. /**
  20. * beforeAction
  21. * @return bool
  22. * @throws Exception
  23. */
  24. public function beforeAction($action)
  25. {
  26. try {
  27. return parent::beforeAction($action);
  28. } catch (\Exception $e) {
  29. throw new Exception($e->statusCode, $e->getMessage());
  30. }
  31. }
  32. }