#1 homexigua
sql:-- phpMyAdmin SQL Dump这是控制器
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 01 月 24 日 16:25
-- 服务器版本: 5.1.41
-- PHP 版本: 5.3.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- 数据库: `db`
--
-- --------------------------------------------------------
--
-- 表的结构 `p_arcticle`
--
CREATE TABLE IF NOT EXISTS `p_arcticle` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(160) NOT NULL,
`content` text NOT NULL,
`pubdate` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
--
-- 转存表中的数据 `p_arcticle`
--
INSERT INTO `p_arcticle` (`id`, `title`, `content`, `pubdate`) VALUES
(1, '第1篇文章标题', '第1篇文章内容', 1264319746),
(2, '第2篇文章标题', '第2篇文章内容', 1264319746),
(3, '第3篇文章标题', '第3篇文章内容', 1264319746),
(4, '第4篇文章标题', '第4篇文章内容', 1264319746),
(5, '第5篇文章标题', '第5篇文章内容', 1264319746),
(6, '第6篇文章标题', '第6篇文章内容', 1264320789),
(7, '第7篇文章标题', '第7篇文章内容', 1264321504);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
class main extends spController
{
//首页显示
function index(){
$db = spClass('arcticle');
$this->list = $db->spPager($this->spArgs('page',1),5)->findAll();
$this->pager = $db->spPager()->getPager();
}
//插入操作
function insert(){
$db = spClass('arcticle');
$arr = array(
'title' => $this->spArgs('title'),
'content' => $this->spArgs('content'),
'pubdate' => time(),
);
if($db->create($arr) !== false){
$this->success('数据添加成功', spUrl("main","index"));
}else{
$this->error('数据添加失败', spUrl('main','index'));
}
}
//查看操作
function view(){
$db = spClass('arcticle');
$id = $this->spArgs('id');
$this->result = $db->find(array('id' => $id));
}
//编辑操作
function edit(){
$db = spClass('arcticle');
$id = $this->spArgs('id');
if($db->find(array('id' => $id))){
$this->result = $db->find(array('id' => $id));
}else{
$this->error('没有查找到数据', spUrl('main','index'));
}
}
//更新操作
function updata(){
$db = spClass('arcticle');
$conditions = array('id' => $this->spArgs('id'));
$arr = array(
'title' => $this->spArgs('title'),
'content' => $this->spArgs('content'),
);
if($db->update($conditions, $arr)){
$this->success('数据更新成功', spUrl('main','index'));
}else{
$this->error('数据更新失败', spUrl('main','index'));
}
}
//删除操作
function delete(){
$db = spClass('arcticle');
$id = $this->spArgs('id');
if($db->deleteByPk($id)){
$this->success('数据删除成功', spUrl('main','index'));
}else{
$this->error('数据删除失败', spUrl('main','index'));
}
}
}
?>
2010-01-25 12:25:30