Exemple #1
0
 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);
 }
 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();
     }
 }