public function actionSearch() { $this->pageTitle = "新闻搜索"; //获得表单提交的数据 $searchType = $_POST["searchType"]; $keyword = $_POST["keyword"]; //搜索记录 $newsInfo = NewsArticles::model()->findAll("{$searchType} like '%{$keyword}%'"); $data = array("newsInfo" => $newsInfo); $this->render("index", $data); }
public function actionIndex($typeId) { $this->pageTitle = "新闻分类"; //查询该分类下所有新闻 $newsInfo = NewsArticles::model()->findAll("typeId={$typeId}"); //查询该分类的详细信息 $newsType = NewsTypes::model()->findByPk($typeId); if ($newsInfo == NULL) { $this->redirect(__APP__ . "/success/index/act/nocontent"); } $data = array("newsInfo" => $newsInfo, "newsType" => $newsType); $this->render("index", $data); }
public function actionIndex() { $this->pageTitle = "天天新闻网"; //新闻总数 $newsCount = NewsArticles::model()->count(); //热点要闻 $sql = "select * from newsArticles a inner join newsTypes b on a.typeId=b.typeId order by hints desc limit 0,6"; $db = Yii::app()->db; $st = $db->createCommand($sql); $hotNews = $st->queryAll(); //一个分类带两条新闻 $newsList = array(); //存储所有记录 $newsModel = NewsArticles::model(); foreach ($this->newsTypes as $v) { $type = array("typeId" => $v["typeId"], "typeName" => $v["typeName"], "articleNums" => $v["articleNums"], "news" => $newsModel->findAll(array("condition" => "typeId={$v["typeId"]}", "order" => "dateandtime desc", "limit" => 2, "offset" => 0))); $newsList[] = $type; } $data = array("newsCount" => $newsCount, "hotNews" => $hotNews, "newsList" => $newsList); $this->render("index", $data); }