/** * @param $id * @return Todo * @throws CHttpException */ private function loadModel($id) { $model = Todo::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'Запрошенная страница не найдена.'); } return $model; }
public function checkSelf() { $messages = []; $count = Todo::model()->countUnfinished(); if (!$count) { return false; } $messages[WebModule::CHECK_NOTICE][] = ['type' => WebModule::CHECK_NOTICE, 'message' => CHtml::link('Невыполненных задач - ' . $count, ['/todo/todoBackend/index'])]; return $messages; }
public function actionUpdate() { $postdata = file_get_contents("php://input"); $post = CJSON::decode($postdata); if (isset($post['id'])) { $model = Todo::model()->findByPk($post['id']); if ($post['note'] == '') { $model->delete(); echo "{}"; return true; } } else { $model = new Todo(); } $model->attributes = $post; $model->user_id = Yii::app()->user->id; $model->save(); echo json_encode($model->attributes); }