Skip to content

Commit

Permalink
优化代码 && 更新说明文件
Browse files Browse the repository at this point in the history
  • Loading branch information
forecho committed Jan 30, 2018
1 parent 895706e commit ff891be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ http://xxxxxxxxxxxxxx/topic/do?type=clap&model=topic&model_id=1
`model` recommend use `Model::tableName()`


http response success(code==200) return json:

```json
{"code":200,"data":0,"message":"success"}
```


http response failure(code==500) return json:

```json
{"code":500,"data":"","message":"{\"model_id\":[\"Model ID不能为空。\"]}"}
```

Demo
------

**ActiveDataProvider Demo 1**

Controller
Expand Down
8 changes: 4 additions & 4 deletions src/actions/ActionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Yii;
use yii\db\Exception;
use yii\helpers\Json;
use yii\web\Response;
use yiier\actionStore\models\ActionStore;

Expand All @@ -25,14 +26,13 @@ public function run()
if (Yii::$app->user->isGuest) {
Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl)->send();
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new ActionStore();
$model->load(array_merge(Yii::$app->request->getQueryParams(), ['user_id' => Yii::$app->user->id]), '');
$model->validate();
if (!$model->errors) {
Yii::$app->response->format = Response::FORMAT_JSON;
if ($model->validate()) {
return ['code' => 200, 'data' => ActionStore::createUpdateAction($model), 'message' => 'success'];
}
return ['code' => 500, 'data' => '', 'message' => json_encode($model->errors)];
return ['code' => 500, 'data' => '', 'message' => Json::encode($model->errors)];
}
}
}
12 changes: 0 additions & 12 deletions src/models/ActionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ public static function createUpdateAction($model)
throw new Exception(json_encode($model->errors));
}

/**
* @param $model ActionStore
* @return false|int
*/
public function destroyAction($model)
{
$data = $this->attributes;
unset($data['id'], $data['created_at'], $data['updated_at'], $data['value']);
return $model->delete();
}


/**
* 返回计数器
* @return int
Expand Down

0 comments on commit ff891be

Please sign in to comment.