/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Ranks the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Ranks::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
protected function processPage($url, $pageContent) { $bookPage = $pageContent; list($rank_best_sell, $info_best_sell, $info_ranks, $title, $isbn_10, $isbn_13) = $this->getPageInfos($bookPage); if (empty($title) || empty($rank_best_sell)) { return false; } if (empty($isbn_13) && empty($isbn_10)) { printf("This has not isbn:\"%s\"\n", $url); return false; } list($main_image, $thumb_image) = $this->getImages($bookPage); $rank = Ranks::model()->find('url=:url', array('url' => $url)); if (empty($rank)) { $rank = new Ranks(); } $rank->url = $url; $rank->rank_best_sell = $rank_best_sell; $rank->info_best_sell = $info_best_sell; $rank->info_ranks = $info_ranks; $rank->title = $title; $rank->isbn_10 = $isbn_10; $rank->isbn_13 = $isbn_13; $rank->main_image = $main_image; $rank->thumb_image = $thumb_image; $rank->utime = date("Y-m-d H:i:s"); try { $rank->save(); } catch (Exception $e) { $this->printException($e); } return true; }