7.投票系统(1)

1.创建表


//选项表 item
create table item(
id bigint unsigned primary key auto_increment,
name varchar(64) not null,
description varchar(128) not null,
vote_count bigint unsigned
)engine MyISAM

//投票的日志表 vote_log
create table vote_log(
id bigint unsigned primary key auto_increment,
ip varchar(20) not null,
vote_date bigint not null,
item_id bigint not null
)engine MyISAM

//过滤 ip 表
create table filter(
id bigint unsigned primary key auto_increment,
ip varchar(20) 
)engine MyISAM

这里写图片描述

AdminController.php

<?php

require_once 'BaseController.php';
require_once APPLICATION_PATH . '/models/Item.php';

class AdminController extends Zend_Controller_Action
{
    public function init()
    {
        $url = constant('APPLICATION_PATH') . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'application.ini';
        $dbconfig = new Zend_Config_Ini($url,'mysql');
        $db = Zend_Db::factory($dbconfig->db);
        $db->query('SET NAMES UTF8');
        Zend_Db_Table::setDefaultAdapter($db);
    }

    public function indexAction()
    {

    }

    //进入到增加选项的页面
    public function addAction()
    {

    }

    //完成一个添加任务
    public function additemAction()
    {
        $name = $this->getRequest()->getParam('name');
        $description = $this->getRequest()->getParam('description');
        $vote = $this->getRequest()->getParam('vote');

        $data = array(
            'name' => $name,
            'description' => $description,
            'vote_count' => $vote
        );

        //先创建一个表模型对象
        $itemModel = new Item();

        //这里成功会返回 id 号,对购物车系统会返回订单号
        $insertId = $itemModel->insert($data);

        $this->render('ok');

    }
}

add.phtml

<h1>
    增加投票选项
</h1>
<form action="/admin/additem" method="post">
    <table>
        <tr>
            <td>name</td>
            <td><input type="text" name="name"/></td>
        </tr>
        <tr>
            <td>描述</td>
            <td><textarea rows="5" cols="30" name="description"></textarea></td>
        </tr>
        <tr>
            <td>初始化投票数</td>
            <td><input type="text" name="vote"/></td>
        </tr>
        <tr>
            <td><input type="submit" value="增加"/></td>
            <td><input type="reset" value="充填"/></td>
        </tr>
    </table>
</form>

index.phtml

<h1>
    后台管理系统
</h1>

<ul>
    <li>
        <a href="#">增加投票选项</a>
    </li>
    <li>
        <a href="#">增加投票选项</a>
    </li>
</ul>

ok.phtml

<script type="text/javascript">
    alert('操作成功');
    history.back();
</script>

Item.php

<?php

//表模型,这里必须继承Zend_Db_Table,否则就不是表模型

class Item extends Zend_Db_Table
{
    protected $_name = 'item'; //表名
    protected $_primary = 'id'; //主键
}

这里写图片描述
这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值