您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ZendFrame实现一个投票模块

2024/4/2 2:05:06发布21次查看
思路分析:获取用户ip,判断该ip 是否被禁用,然后判断今天有没有投了 再做出相应的操作...
主要步骤如下:
配置一下application.ini 让项目可以连接到指定的数据库
[mysql]
db.adapter = pdo_mysql
db.params.host = localhost
db.params.username = root
db.params.password =
db.params.dbname=votedb
初始化数据库适配器
db);
  zend_db_table::setdefaultadapter($db);
  }
 }
//创建表模型
getparam('itemid','no');  //获取id
//用于获取ip 地址$_server['remote_addr']
  $ip = $this->getrequest()->getserver('remote_addr');
  //看看这个ip是否被禁用
  $filtermodel = new filter();
  $filters =  $filtermodel->fetchall(ip='$ip')->toarray();
  if(count($filters)>=1){
  $this->view->info=你被警用了!;
  //成功,跳转到一个全局的视图
  $this->_forward('err','global');
  return;
  }
//先看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');
}
}
}
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product