/** * Action - todo/update * update task * * @param int $id The task id * @return string */ public function updateAction($id) { $models = $this->app['models']; //----------------- try { // Initialization $this->init(__CLASS__ . "/" . __FUNCTION__); // Create object newTask and set values $task = new Todo(); $task->setApp($this->app); $task->setResolveValues($this->params); // use a validator to check the values $errorList = $this->validate($task); if ($errorList !== TRUE && count($errorList)) { $errMessage = $this->getMsgErrorValid($errorList); $this->app->abort(400, $errMessage); } $data = $models->load('Todo', 'updateTask', $task->getValues()); return $this->sendJson($data); } catch (\Exception $exc) { return $this->errorAjax($exc); } }
/** * readTasks * Read tasks * * @return array */ public function readTasks() { $db = $this->app['db']; $norm_tasks = array(); //-------------------- // Get user's posts $sql = "SELECT * FROM todo"; $tasks = $db->fetchAll($sql); if (is_array($tasks) && count($tasks)) { foreach ($tasks as $task) { $norm_tasks[] = Todo::normalizeValues($task, $this->app); } } return $norm_tasks; }