Zend framework 之投票系统流程图

来源:互联网 发布:网络运营推广岗位职责 编辑:程序博客网 时间:2024/05/22 10:46

对应于制器中的代码

//以下代码为学习代码

<?php
require_once 'BaseController.php';
require_once APPLICATION_PATH.'/models/Item.php';
require_once APPLICATION_PATH.'/models/VoteLog.php';


class VoteController extends BaseController{
public function voteAction(){

$item_id = $this->getRequest()->getParam('itemid','no');  //获取id
//用于获取ip 地址$_SERVER['REMOTE_ADDR']
//先看voteLOg 这个表今天有没有透过一次
$today=date('Ymd');//今天的时间
$voteLogModel = new VoteLog();
$where = "ip='$ip' AND vote_date=$today";
$res = $voteLogModel->fetchAll($where)->toArray();
if(count($res)>0){  //如果大于0表示已经投 了
$this->render('error');
return ;
}else{
//更新item的vote_count,添加更新日志
$data = array(
'ip' => $ip,
'vote_date'=>$today,
'item_id'=>$item_id
);
if($voteLogModel->insert($data)>0){  //如果更新成功要更改item 表
$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');
}
}
}


?>

原创粉丝点击