public function homeAction() { // action body // echo $_COOKIE["account"]; // print_r( $this->cookie); $imgpath = $_SERVER['DOCUMENT_ROOT'] . "/WebOne/public/image/head/"; $id = $_SESSION["userinfo"][0][id]; // print_r($_SESSION["userinfo"][0]); $userinfo = new userinfoModel(); $db = $userinfo->getAdapter(); $user = $db->query('SELECT * FROM userinfo where userid=?', $id)->fetchAll()[0]; $activitys = new ActivityModel(); $db1 = $activitys->getAdapter(); $hotactivity = $db1->query('select * from activity order by nums desc limit 0,1')->fetchAll()[0]; $questions = new QuestionModel(); $db2 = $questions->getAdapter(); $hotquestion = $db2->query('select * from question order by answernum desc limit 0,1')->fetchAll()[0]; if (file_exists($imgpath . $id . ".jpg")) { $this->view->path = $baseUrl . "/WebOne/public/image/head/" . $id . ".jpg"; } else { $this->view->path = $baseUrl . "/WebOne/public/image/initial.jpg"; } $userid = $hotquestion[userid]; $Usertable = new UserModel(); $db3 = $Usertable->getAdapter(); $name = $db3->query('select name from User where id=?', $userid)->fetchAll()[0][name]; $this->view->user = $user; $this->view->info = $_SESSION["userinfo"]; $this->view->activity = $hotactivity; $this->view->question = $hotquestion; $this->view->name = $name; }
public function myquestionAction() { $page = $this->getRequest()->getParam('page'); $account = $_COOKIE["account"]; $usertable = new UserModel(); $db1 = $usertable->getAdapter(); $questiontable = new QuestionModel(); $db2 = $questiontable->getAdapter(); //查找当前用户ID $result = $usertable->fetchRow($db1->quoteInto('email = ?', $account))->toArray(); $uid = $result['id']; //查找用户question // $questions = $questiontable-> fetchRow($db2->quoteInto('userid = ?', $uid)) ->toArray(); $num = $db2->query('SELECT COUNT(*) as num FROM question,User WHERE question.userid = User.id and User.id =? order by time desc', $uid)->fetchAll()[0][num]; //$num=count($questions); $pages = ceil($num / 3); if ($page == "") { $page = 0; } //确定页面显示的规范 处理分页的逻辑 if ($page < 3) { if ($pages > 3) { $set = array(1, 2, 3, 4); } else { $set = array(); for ($i = 1; $i <= $pages; $i++) { $set[] = $i; } } } else { if ($page >= 3) { if ($page + 3 <= $pages) { $set = array($page, $page + 1, $page + 2, $page + 3); } else { $set = array(); for ($i = $page; $i <= $pages; $i++) { $set[] = $i; } } } } $where = $db2->quoteInto('userid=?', $uid); $order = 'begin desc'; $count = 3; $offset = $page * 3; $questions = $questiontable->fetchAll($where, $order, $count, $offset)->toArray(); $this->view->results = $questions; $this->view->user = $result; $this->view->page = $page; $this->view->count = $set; }