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'; //主键
}