diff --git a/backend/actions/CreateAction.php b/backend/actions/CreateAction.php index 0093d091..ef13fda1 100644 --- a/backend/actions/CreateAction.php +++ b/backend/actions/CreateAction.php @@ -12,6 +12,7 @@ use stdClass; use backend\actions\helpers\Helper; use yii\base\Exception; +use yii\web\Response; use yii\web\UnprocessableEntityHttpException; /** @@ -103,6 +104,7 @@ public function run() $createResult = call_user_func_array($this->doCreate, $createData);//call doCreate closure if (Yii::$app->getRequest()->getIsAjax()) { //ajax + Yii::$app->getResponse()->format = Response::FORMAT_JSON; if ($createResult === true) {//only $createResult is true represent create success return ['code' => 0, 'msg' => 'success', 'data' => new stdClass()]; } else { diff --git a/backend/actions/DeleteAction.php b/backend/actions/DeleteAction.php index 74eaff05..61b6727c 100644 --- a/backend/actions/DeleteAction.php +++ b/backend/actions/DeleteAction.php @@ -15,6 +15,7 @@ use yii\base\Exception; use yii\web\BadRequestHttpException; use yii\web\MethodNotAllowedHttpException; +use yii\web\Response; use yii\web\UnprocessableEntityHttpException; /** @@ -77,12 +78,14 @@ public function run() if (count($errors) == 0) { if( Yii::$app->getRequest()->getIsAjax() ) { + Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ['code'=>0, 'msg'=>'success', 'data'=>new stdClass()]; }else { return $this->controller->redirect(Yii::$app->getRequest()->getReferrer()); } } else { if( Yii::$app->getRequest()->getIsAjax() ){ + Yii::$app->getResponse()->format = Response::FORMAT_JSON; throw new UnprocessableEntityHttpException(implode("
", $errors)); }else { Yii::$app->getSession()->setFlash('error', implode("
", $errors)); diff --git a/backend/actions/DoAction.php b/backend/actions/DoAction.php index 76079b20..1e7cbc8a 100644 --- a/backend/actions/DoAction.php +++ b/backend/actions/DoAction.php @@ -12,6 +12,7 @@ use stdClass; use backend\actions\helpers\Helper; use yii\base\Exception; +use yii\web\Response; use yii\web\UnprocessableEntityHttpException; /** @@ -91,6 +92,7 @@ public function run() if (Yii::$app->getRequest()->getIsAjax()) { //ajax if ($doResult === true) {//only $doResult is true represent create success + Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ['code' => 0, 'msg' => 'success', 'data' => new stdClass()]; } else {//not ajax throw new UnprocessableEntityHttpException(Helper::getErrorString($doResult)); diff --git a/backend/actions/SortAction.php b/backend/actions/SortAction.php index 9c3cde0c..3b0e9092 100644 --- a/backend/actions/SortAction.php +++ b/backend/actions/SortAction.php @@ -15,6 +15,7 @@ use yii\base\Exception; use yii\base\InvalidArgumentException; use yii\web\MethodNotAllowedHttpException; +use yii\web\Response; use yii\web\UnprocessableEntityHttpException; /** @@ -72,6 +73,7 @@ public function run() $result = call_user_func_array($this->doSort, [$condition, $value, $this]); if (Yii::$app->getRequest()->getIsAjax()) { + Yii::$app->getResponse()->format = Response::FORMAT_JSON; if( $result === true ){ return ['code'=>0, 'msg'=>'success', 'data'=>new stdClass()]; }else{ diff --git a/backend/actions/UpdateAction.php b/backend/actions/UpdateAction.php index 7b2604e6..4beae2f1 100644 --- a/backend/actions/UpdateAction.php +++ b/backend/actions/UpdateAction.php @@ -14,6 +14,7 @@ use Closure; use backend\actions\helpers\Helper; use yii\base\Exception; +use yii\web\Response; use yii\web\UnprocessableEntityHttpException; /** @@ -108,6 +109,7 @@ public function run() $updateResult = call_user_func_array($this->doUpdate, $updateData);//call doUpdate closure if( Yii::$app->getRequest()->getIsAjax() ){ //ajax + Yii::$app->getResponse()->format = Response::FORMAT_JSON; if( $updateResult === true ){//only $updateResult is true represent update success return ['code'=>0, 'msg'=>'success', 'data'=>new stdClass()]; }else{ diff --git a/backend/widgets/ueditor/UeditorAction.php b/backend/widgets/ueditor/UeditorAction.php index 201b717b..68a85f7d 100755 --- a/backend/widgets/ueditor/UeditorAction.php +++ b/backend/widgets/ueditor/UeditorAction.php @@ -454,12 +454,16 @@ protected function manage($allowFiles, $listSize, $path) /* 获取文件列表 */ $path = Yii::getAlias('@ueditor') . (substr($path, 0, 1) == '/' ? '' : '/') . $path; $files = $this->getFiles($path, $allowFiles); - if (! count($files)) { + $len = 0; + if( $files !== null ){ + $len = count($files); + } + if ( $len == 0 ) { $result = [ 'state' => 'no match file', 'list' => [], 'start' => $start, - 'total' => count($files), + 'total' => $len, ]; return $result; } @@ -473,7 +477,7 @@ protected function manage($allowFiles, $listSize, $path) 'state' => 'SUCCESS', 'list' => $list, 'start' => $start, - 'total' => count($files), + 'total' => $len, ]; return $result; }