韩顺平 zend framework 视频教程 源代码和笔记心得第5讲——第6讲 投票系统源代码

来源:互联网 发布:2017零售业数据分析 编辑:程序博客网 时间:2024/03/29 00:43


没啥好说的,直接上源代码 ,多上机,多联系。

http://download.csdn.net/detail/ibmfahsion/4460772


数据库下载地址:

http://download.csdn.net/detail/ibmfahsion/4460807


核心代码:

<?php
require_once 'BaseController.php';
require_once APPLICATION_PATH.'/models/Item.php';
require_once APPLICATION_PATH.'/models/VoteLog.php';
/**
 * 专门管理后台
 * Enter description here ...
 * @author harry_manage_top_100
 *
 */
class VoteController extends BaseController
{


    public function init()
    {
        /* Initialize action controller here */
    }


    public function indexAction()
    {
        // action body
    }


   
  public function voteAction()
    {
        // action body
      /*  echo 'toupiao';
        exit();*/
    //获取用户投票的id
    $item_id=$this->getRequest()->getParam('itemid','no');
    //$this->getResponse();
    $ip=$this->getRequest()->getServer('REMOTE_ADDR');
    $today=date('ymd');//20120801
    /* echo $item_id.'--'.$ip;
    exit();*/
   
    //先看看vote_log这个表中今天是否投过一次
    $voteLogModel=new voteLog();
    //sql注入先不考虑
    $where="ip='$ip' AND vote_date=$today";
    $res=$voteLogModel->fetchAll($where)->toArray();
   
    /*echo $today.'----';
    echo '<br>'.$where;
    echo '<br>'.count($res);
    exit();*/
    if(count($res)>95){
    //提示一句话
    $this->render('error');
    return;
    }else{
    //更新item的vote_count,添加这个人的投票日志
    $data=array(
    'ip'=>$ip,
    'vote_date'=>$today,
    'item_id'=>$item_id
    );
    if($voteLogModel->insert($data)>0){
    $itemModel=new Item();
   
    //通过主键直接获取对应的item
    $item=$itemModel->find($item_id)->toArray();
           $newvote=$item[0]['vote_count']+1;
    $set=array(
    'vote_count'=>$newvote
    );
    $where="id=$item_id";
    $itemModel->update($set,$where);
    }
   
    $this->render('ok');
    }
   
    }
}


原创粉丝点击