| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace addons\SmartForm\backend\controllers;
- use Yii;
- use common\controllers\AddonsController;
- use yii\web\UnauthorizedHttpException;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\SmartForm\backend\controllers
- */
- class BaseController extends AddonsController
- {
- /**
- * @var string
- */
- // public $layout = "@addons/SmartForm/backend/views/layouts/main";
- /**
- * @param $action
- * @return bool
- * @throws UnauthorizedHttpException
- * @throws \yii\web\BadRequestHttpException
- */
- public function beforeAction($action)
- {
- try {
- if (!parent::beforeAction($action)) {
- return false;
- }
- return true;
- } catch (UnauthorizedHttpException $e) {
- $request = \Yii::$app->request;
- $is_ajax = $request->isAjax;
- if ($is_ajax) {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- \Yii::$app->response->data = ['code' => 1, 'msg' => $e->getMessage()];
- \Yii::$app->response->send();
- return false;
- } else {
- $this->layout = 'exception';
- return $this->render('index');
- // throw new UnauthorizedHttpException($e->getMessage());
- }
- }
- }
- }
|