WIKI使用導(dǎo)航
站長百科導(dǎo)航
站長專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營銷
- 虛擬主機(jī)管理系統(tǒng)
- 開放平臺
- WIKI程序與應(yīng)用
- 美國十大主機(jī)
ThinkSNS-應(yīng)用開發(fā)范例-開始編程ACTION層
來自站長百科
導(dǎo)航: 上一頁
ACTION層
在Lib/Action/目錄下,建立IndexAction.class.php,并增加以下程序。下面的程序已經(jīng)附上最詳細(xì)的注釋了。
<?php class IndexAction extends Action{ private $gift; //禮品表模型 private $gift_category; //禮品類型表模型 private $user_gift; //用戶送禮記錄表模型 /** * 初始化函數(shù) * */ function _initialize(){ //參數(shù)轉(zhuǎn)義 new_addslashes($_POST); new_addslashes($_GET); //整個應(yīng)用的賦值 $this->gift = D('Gift'); $this->gift_category = D('GiftCategory'); $this->user_gift = D('UserGift'); $this->user_gift->setApi($this->api); $this->user_gift->setGift($this->gift); $this->user_gift->setCategory($this->gift_category); $this->gift_category->setGift($this->gift); $mid = $this->mid; $config = D('AppConfig')->getConfig(); $this->assign('config',$config); } /** * 禮物中心 * */ function index() { //獲取分組好的禮物列表 $giftList = $this->gift_category->GiftToCategory(); //把用戶姓名和頭像賦值給模板 $this->__assignNameAndFace(intval($_GET['uid'])); //賦值給模板 $this->assign('categorys',$giftList); $this->display(); } /** * 收到的禮物 * */ function receivebox(){ //獲取收到的禮物列表 $gift = $this->user_gift->receiveList($this->mid); $this->assign('gifts',$gift); $this->display(); } /** * 某人的禮物 * */ function personal(){ //獲取用戶ID $uid = intval($_GET['uid']); if(empty($uid)){ $this->error('非法操作!'); } $this->assign('uid',$uid); //獲取收到的禮物列表 if(isset($_GET['isSend'])) { $gift = $this->user_gift->sendList($uid); $this->assign('on2','on'); }else{ $gift = $this->user_gift->receiveList($uid); $this->assign('on1','on'); } $this->assign('gifts',$gift); $this->display(); } /** * 送出的禮物 * */ function sendBox(){ //獲取送出的禮物列表 $gift = $this->user_gift->sendList($this->mid); $this->assign('gifts',$gift); $this->display(); } /** * 送出禮物 * */ function send(){ //獲取當(dāng)前用戶的ID 和姓名 $fromUid = $this->mid; $fromUserName = $this->my_name; //獲取要發(fā)送的好友ID,如有不明可參考'好友選擇widget'的說明 $toUserId = $_POST['fri_ids']; if(empty($toUserId)){ $this->error('你還沒有選擇好友'); exit; } //獲取附加信息 $sendInfo['sendInfo'] = t($_POST['sendInfo']); //獲取發(fā)送方式 $sendInfo['sendWay'] = t($_POST['sendWay']); //獲取禮品ID 并用t 函數(shù)過濾 $giftId = t($_POST['giftId']); //查詢數(shù)據(jù)庫獲取禮品的全部信息 $giftInfo = $this->gift->where('id='。$giftId)->find(); //發(fā)送禮品 $result = $this->user_gift- >sendGift($toUserId,$fromUid,$fromUserName,$sendInfo,$giftInfo); if($result==1){ //如果發(fā)送成功就跳到‘送出的禮品’頁面 $this->redirect('sendbox'); }else{ //如果發(fā)送失敗就跳轉(zhuǎn)到錯誤提示頁并顯示失敗原因 $this->error($result); } } /** * 把用戶姓名和頭像賦值給模板 * */ private function __assignNameAndFace($uid){ if($uid && $uid != $this->mid){ $toUserName = getUserName($uid); $toUserFace = getUserFace($uid); $this->assign('toUserName',$toUserName); $this->assign('toUserFace',$toUserFace); } } } ?>