コード例 #1
0
ファイル: ToDoList.php プロジェクト: sintret/yii2-todolist
 public function send()
 {
     $post = $this->post;
     if ($post) {
         $id = isset($post['id']) ? (int) $post['id'] : null;
         $type = isset($post['type']) ? (int) $post['type'] : 0;
         $title = $post['title'];
         if ($id) {
             $model = static::findOne($id);
             $model->status = 1;
             $model->save();
         }
         if ($title) {
             $model = new \sintret\todolist\models\ToDoList();
             $model->title = $title;
             $model->userId = Yii::$app->user->id;
             $model->save();
         }
     }
     return $model->data($type);
 }
コード例 #2
0
 public function actionTodolist()
 {
     $id = (int) $_POST['id'];
     $title = $_POST['title'];
     $type = (int) $_POST['type'];
     if ($id) {
         $model = \sintret\todolist\models\ToDoList::findOne($id);
         $model->status = 1;
         $model->save();
     } elseif ($title) {
         $model = new \sintret\todolist\models\ToDoList();
         $model->title = $title;
         $model->userId = Yii::$app->user->id;
         if ($model->save()) {
             echo $model->data();
         }
     } elseif (isset($_POST['type'])) {
         $model = new \sintret\todolist\models\ToDoList();
         echo $model->data($type);
     } else {
         $model = new \sintret\todolist\models\ToDoList();
         echo $model->data();
     }
 }