public function actionAdd() { //获得表单提交的数据 $title = $_POST["title"]; $clickTimes = $_POST["clickTimes"]; //添加记录 $bbsInfo = new BbsInfo(); $bbsInfo->title = $title; $bbsInfo->clickTimes = $clickTimes; $result = $bbsInfo->save(); echo $result; }
public function actionIndex() { $this->pageTitle = "分页类"; //使用分页类 $page = new Page(BbsInfo::model()->count(), 3); $bbsInfo = BbsInfo::model()->findAll(array("limit" => $page->listRows, "offset" => $page->firstRow)); $data = array("bbsInfo" => $bbsInfo, "pageList" => $page->show()); $this->render("index", $data); }
public function actionUpdate($bbsId) { //$result = BbsInfo::model()->updateAll($_POST,"bbsId={$bbsId}"); $result = BbsInfo::model()->updateByPk($bbsId, $_POST); if ($result > 0) { $this->redirect(__APP__ . "/query/index"); } else { $this->redirect(__APP__ . "/update/index/bbsId/{$bbsId}"); } }
public function actionIndex($currentPage = 1) { $this->pageTitle = "数据库分页"; //分页变量 $pageSize = 3; $totalRow = BbsInfo::model()->count(); $totalPage = ceil($totalRow / $pageSize); $start = ($currentPage - 1) * $pageSize; $bbsInfo = BbsInfo::model()->findAll(array("limit" => $pageSize, "offset" => $start)); $data = array("bbsInfo" => $bbsInfo, "currentPage" => $currentPage, "totalPage" => $totalPage); $this->render("index", $data); }
public function actionAdd() { $model = BbsInfo::model(); // 使用$model->$var来绑定数据 $model->title = $_POST['title']; $model->userId = $_SESSION['userMsg']['userId']; $model->typeId = $_POST['typeId']; $model->face = $_POST['face']; $model->content = $_POST['content']; // save保存方法保存数据 $result = $model->save(); // 跳转 $this->redirect("index.php?r=reaction/index/act/addBbs/rst/{$result}"); }
public function actionIndex() { $this->pageTitle = "论坛首页"; // 论坛公告 $notices = Notices::model()->find(); // 讨论区类别 $bbsType = BbsType::model()->findAll(); // 话题计数 $bbsCount = BbsInfo::model()->count(); // 回帖计数 $revCount = Reviews::model()->count(); // 用户计数 $userCount = UserInfo::model()->count(); // 绑定数据 $data = array('notices' => $notices, 'bbsType' => $bbsType, 'bbsCount' => $bbsCount, 'revCount' => $revCount, 'userCount' => $userCount); $this->render('index', $data); }
/** * 通过获取的bbsId来删除话题,只有发帖人和超级管理员能删除 * @param int $bbsId 论坛话题ID */ public function actionDelete($bbsId) { $result = BbsInfo::model()->deleteByPK("{$bbsId}"); $this->redirect('index.php?r=reaction/index/act/delArtical/rst/' . $result . 'bbsId/' . $bbsId); }
<?php header("content-type:text/html;charset=utf-8"); include_once 'dbio/BbsInfo.php'; $bbsInfo = BbsInfo::getBbsInfo(); //所有记录 ?> <!DOCTYPE html> <html> <head> <title>数据库操作</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body> <table border="1" align="center" width="600"> <tr> <td>编号</td> <td>标题</td> <td>点击次数</td> <td>时间</td> </tr> <?php foreach ($bbsInfo as $v) { echo "<tr>"; echo " <td>{$v[0]}</td>"; echo " <td>{$v[1]}</td>"; echo " <td>{$v[2]}</td>"; echo " <td>{$v[3]}</td>"; echo "</tr>"; } ?>
public function actionDelete($bbsId) { //$result = BbsInfo::model()->deleteAll("bbsId={$bbsId}"); $result = BbsInfo::model()->deleteByPk($bbsId); $this->redirect(__APP__ . "/query/index"); }