예제 #1
0
 private function _addSave()
 {
     $todoData = $this->getParam('todo');
     if (empty($todoData['todo_id'])) {
         $todo = new Todo();
         $todo->todo_account = 1;
     } else {
         $todo = Todo::findOne($todoData['todo_id']);
     }
     $todo->setAttributes($this->getParam('todo'));
     if (!$todo->save()) {
         $this->renderJson([], 1, current($todo->getErrors()));
     }
 }
예제 #2
0
 /**
  * Finds the Todo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Todo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Todo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }