1. 控制器 =》 shopApplication/Admin/Controller/GoodsController.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 上午11:07
*/
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
public function add(){
if(IS_POST){
$goodsModel = D('Goods'); //调用数据库 Goods
$goodsModel->create(); //收集请求中的数据到自身上.. 对表单数据进行验证...对数据进行自动完成的操作..
if($goodsModel->add()){ //添加
$this->success('保存成功',U('index'));
}else{
$this->error('保存失败!'.$goodsModel->getError());
}
}else{
$this->display('edit');
}
}
-----------------------**************--------------------*************---------------
2. 模型 =》 shopApplication/Admin/Model/GoodsModel.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 下午2:08
*/
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
/* //配置该模型对应的特有前缀
protected $tablePrefix = 'beijing_';
//修改该模型操作的表名
protected $tableName = 'product';
//直接指定让其操作的表名
protected $trueTableName = 'xxxxxxxxxxx';*/
}
------------------------************----------------*************-----------------
3.视图 shopApplication/Admin/View/Goods/edit.html
<!-- $Id: brand_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ECSHOP 管理中心 - {$meta_title} </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
<link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
<span class="action-span"><a href="brandList.html">商品商品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - {$meta_title} </span>
<div style="clear:both"></div>
</h1>
<div class="main-div">
<form method="post" action="{:U()}" enctype="multipart/form-data" >
<table cellspacing="1" cellpadding="3" width="100%">
<tr>
<td class="label">商品名称</td>
<td>
<input type="text" name="goods_name" maxlength="60" value="{$goods->goods_name}" />
<span class="require-field">*</span>
</td>
</tr>
<tr>
<td class="label">商品价格</td>
<td>
<input type="text" name="goods_price" value="{$goods:goods_price}" />
</td>
</tr>
<tr>
<td class="label">商品数量</td>
<td>
<input type="text" name="goods_number" value="{$goods_number}" />
</td>
</tr>
<tr>
<td class="label">商品描述</td>
<td>
<textarea name="goods_introduce" cols="60" rows="4" ></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br />
<input type="submit" class="button" value=" 确定 " />
<input type="reset" class="button" value=" 重置 " />
</td>
</tr>
</table>
</form>
</div>
<div id="footer">
共执行 1 个查询,用时 0.018952 秒,Gzip 已禁用,内存占用 2.197 MB<br />
版权所有 © 2005-2012 上海商派网络科技有限公司,并保留所有权利。</div>
</body>
</html>
------------------************-----------------***************---------------
4.效果图:
5.数据库 thinkphp0421.sql
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50524
Source Host : 127.0.0.1:3306
Source Database : thinkphp0421
Target Server Type : MYSQL
Target Server Version : 50524
File Encoding : 65001
Date: 2014-06-23 18:32:24
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for beijing_user
-- ----------------------------
DROP TABLE IF EXISTS `beijing_user`;
CREATE TABLE `beijing_user` (
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of beijing_user
-- ----------------------------
-- ----------------------------
-- Table structure for itcast_c_user
-- ----------------------------
DROP TABLE IF EXISTS `itcast_c_user`;
CREATE TABLE `itcast_c_user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
`age` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of itcast_c_user
-- ----------------------------
INSERT INTO `itcast_c_user` VALUES ('1', '刘备', '27');
INSERT INTO `itcast_c_user` VALUES ('2', '关羽', '26');
INSERT INTO `itcast_c_user` VALUES ('3', '张飞', '25');
INSERT INTO `itcast_c_user` VALUES ('4', '赵云', '24');
INSERT INTO `itcast_c_user` VALUES ('5', '黄忠', '23');
INSERT INTO `itcast_c_user` VALUES ('6', '马超', '22');
INSERT INTO `itcast_c_user` VALUES ('7', '魏延', '21');
INSERT INTO `itcast_c_user` VALUES ('8', '1111', '111');
-- ----------------------------
-- Table structure for itcast_goods
-- ----------------------------
DROP TABLE IF EXISTS `itcast_goods`;
CREATE TABLE `itcast_goods` (
`goods_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`goods_name` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品名称',
`goods_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '价格',
`goods_number` int(11) NOT NULL DEFAULT '100' COMMENT '数量',
`goods_category_id` int(11) DEFAULT NULL,
`goods_introduce` text COLLATE utf8_unicode_ci COMMENT '详细介绍',
`goods_big_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品图片',
`goods_small_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品小图',
`goods_create_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
`goods_last_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`goods_id`)
) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='商品表';
-- ----------------------------
-- Records of itcast_goods
-- ----------------------------
INSERT INTO `itcast_goods` VALUES ('2', '诺基亚N855qq', '1000.00', '201', '3', '货品简介', '', '', '1242110760', '1376313168');
INSERT INTO `itcast_goods` VALUES ('3', '诺基亚666原装充ee电器', '33.00', '102', '0', '货品简介', '', '', '1241422082', '1376313495');
INSERT INTO `itcast_goods` VALUES ('4', '诺基亚N85原装充电器', '111.00', '222', '8', '货品简介', '', '', '1241422402', '0');
INSERT INTO `itcast_goods` VALUES ('6', '胜创KIN33GMAX', '42.00', '15', '0', '货品简介', '', '', '1241422573', '1376313927');
INSERT INTO `itcast_goods` VALUES ('7', '诺基亚N85原装立体声耳机HS-82', '100.00', '20', '0', '货品简介', '', '', '1241422785', '1376309276');
INSERT INTO `itcast_goods` VALUES ('8', '飞利浦6@6v', '1200.00', '55', '3', '货品简介', '', '', '1241425512', '0');
INSERT INTO `itcast_goods` VALUES ('9', '诺基亚E33', '5000.00', '4', '3', '货品简介', '', '', '1241511871', '0');
INSERT INTO `itcast_goods` VALUES ('10', '索爱C706', '1500.00', '7', '3', '货品简介', '', '', '1241965622', '0');
INSERT INTO `itcast_goods` VALUES ('11', '索爱C702c', '1300.00', '1', '3', '货品简介', '', '', '1241966951', '0');
INSERT INTO `itcast_goods` VALUES ('12', '摩托罗拉A810', '983.00', '8', '3', '货品简介', '', '', '1245297652', '0');
INSERT INTO `itcast_goods` VALUES ('13', '诺基亚5320 XpressMusic', '1311.00', '8', '4', '货品简介', '', '', '1241967762', '0');
INSERT INTO `itcast_goods` VALUES ('14', '诺基亚5800XM', '2625.00', '1', '3', '货品简介', '', '', '1241968492', '0');
INSERT INTO `itcast_goods` VALUES ('15', '摩托罗拉A810', '788.00', '3', '2', '货品简介', '', '', '1241968703', '0');
INSERT INTO `itcast_goods` VALUES ('16', '恒基伟业G101', '823.33', '0', '3', '货品简介', '', '', '1241968949', '0');
INSERT INTO `itcast_goods` VALUES ('17', '夏新N7', '2300.00', '1', '4', '货品简介', '', '', '1241969394', '0');
INSERT INTO `itcast_goods` VALUES ('18', '夏新T5', '2878.00', '1', '3', '货品简介', '', '', '1241969533', '0');
INSERT INTO `itcast_goods` VALUES ('19', '三星SGH-F258', '858.00', '12', '3', '货品简介', '', '', '1241970139', '0');
INSERT INTO `itcast_goods` VALUES ('20', '三星BC01', '280.00', '12', '3', '货品简介', '', '', '1241970417', '0');
INSERT INTO `itcast_goods` VALUES ('21', '金立 A30', '2000.00', '40', '3', '货品简介', '', '', '1241970634', '0');
INSERT INTO `itcast_goods` VALUES ('22', '多普达Touch HD', '5999.00', '1', '5', '货品简介', '', '', '1241971076', '0');
INSERT INTO `itcast_goods` VALUES ('23', '诺基亚N97', '4000.00', '8', '3', '货品简介', '', '', '1241971488', '1376313982');
INSERT INTO `itcast_goods` VALUES ('24', 'P807', '2000.00', '100', '13', '货品简介', '', '', '1241971981', '0');
INSERT INTO `itcast_goods` VALUES ('25', '小灵通/固话50元充值卡', '48.00', '2', '13', '货品简介', '', '', '1241972709', '0');
INSERT INTO `itcast_goods` VALUES ('26', '小灵通/固话20元充值卡', '19.00', '2', '0', '货品简介', '', '', '1241972789', '0');
INSERT INTO `itcast_goods` VALUES ('27', '联通100元充值卡', '95.00', '2', '15', '货品简介', '', '', '1241972894', '1376309295');
INSERT INTO `itcast_goods` VALUES ('28', '联通50元充值卡', '45.00', '0', '14', '货品简介', '', '', '1241972976', '0');
INSERT INTO `itcast_goods` VALUES ('29', '移动100元充值卡', '90.00', '0', '14', '货品简介', '', '', '1241973022', '0');
INSERT INTO `itcast_goods` VALUES ('30', '移动20元充值卡', '18.00', '9', '3', '货品简介', '', '', '1241973114', '0');
INSERT INTO `itcast_goods` VALUES ('31', '摩托罗拉E8 ', '1337.00', '1', '0', '货品简介', '', '', '1242110412', '0');
INSERT INTO `itcast_goods` VALUES ('32', 'htc_one', '3999.00', '25', '23', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('33', 'htc_s', '3456.00', '12', '23', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('34', 'htc_ss', '3456.00', '12', '0', '货品简介', '', '', '1370660527', '0');
INSERT INTO `itcast_goods` VALUES ('35', 'apple5s', '5999.00', '34', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('36', 'LV包', '12000.00', '13', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('37', '三星耳机', '109.00', '59', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('39', 'HTC_one', '3555.00', '100', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('41', '三星耳机', '109.00', '59', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('44', '南孚34电池', '50.00', '59', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('45', '波导手机333', '1200.00', '40', '4', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('47', 'haier999', '3210.00', '101', '0', '货品简介', '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('56', '新货品1新货品1', '100.00', '20', null, null, '', '', '1403514677', '1403514677');
INSERT INTO `itcast_goods` VALUES ('57', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('58', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('59', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('60', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('61', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('62', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('63', '新货品1', '1001.00', '501', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('64', '新货品', '100.00', '50', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('65', '新货品', '100.00', '50', null, null, '', '', '0', '0');
INSERT INTO `itcast_goods` VALUES ('66', '新货品', '100.00', '50', null, null, '', '', '0', '0');
-- ----------------------------
-- Table structure for itcast_user
-- ----------------------------
DROP TABLE IF EXISTS `itcast_user`;
CREATE TABLE `itcast_user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`username` varchar(128) NOT NULL DEFAULT '' COMMENT '登录名',
`password` varchar(32) NOT NULL DEFAULT '' COMMENT '登录密码',
`user_email` varchar(64) NOT NULL DEFAULT '' COMMENT '邮箱',
`user_sex` tinyint(4) NOT NULL DEFAULT '1' COMMENT '性别',
`user_qq` varchar(32) NOT NULL DEFAULT '' COMMENT 'qq',
`user_tel` varchar(32) NOT NULL DEFAULT '' COMMENT '手机',
`user_xueli` tinyint(4) NOT NULL DEFAULT '1' COMMENT '学历',
`user_hobby` varchar(32) NOT NULL DEFAULT '' COMMENT '爱好',
`user_introduce` text COMMENT '简介',
`user_time` int(11) DEFAULT NULL,
`last_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8 COMMENT='会员表';
-- ----------------------------
-- Records of itcast_user
-- ----------------------------
INSERT INTO `itcast_user` VALUES ('1', 'zhangsanff', '1234', 'zhangsan@163.com', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('3', 'jack', 'jack', 'tom@163.com', '1', '', '', '1', '', null, null, '0');
INSERT INTO `itcast_user` VALUES ('98', 'linken', 'abcd', 'lin@q.com', '1', '78347832', '13245671234', '4', '', 'I am linken', null, '0');
INSERT INTO `itcast_user` VALUES ('100', 'tom', 'tom', 'tom@q.com', '3', '263872', '13465432345', '5', '1,3', 'I am tom', null, '0');
INSERT INTO `itcast_user` VALUES ('113', '', '1234', '', '1', '', '13425364536', '5', '1,4', 'I am aobama', null, '0');
INSERT INTO `itcast_user` VALUES ('114', 'xiaoming', 'ming', 'ming@m.com', '1', '9273982', '1349874834', '4', '1,3,4', 'I am xiaoming', null, '0');
INSERT INTO `itcast_user` VALUES ('115', 'xiaoqiang', 'qiang', 'qiang@q.com', '1', '92382738', '13425364536', '4', '1,3,4', 'qiang', '1385107783', '0');
INSERT INTO `itcast_user` VALUES ('116', 'xiaomingg', '1234', 'q@q.com', '1', '92382738', '13425364536', '3', '1,2,3', 'sdfs', '92382738', '0');
INSERT INTO `itcast_user` VALUES ('117', 'tom', '1234', 'tom@q.com', '1', '297398273', '13245673214', '5', '', 'I am tom', null, '0');
INSERT INTO `itcast_user` VALUES ('118', 'slkjdlks', 'lsjdksjd', '', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('119', 'linken', '1234', '', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('120', 'zhangsan', '123', 'zhangsan@qq.com', '1', '2398273', '329492843', '5', '', 'I am zhangsan', null, '0');
INSERT INTO `itcast_user` VALUES ('121', 'xiaoli', 'abc', 'xiaoli@q.com', '1', '24234', '24323432', '4', '2,3,4', 'i am xiaoli', null, '0');
INSERT INTO `itcast_user` VALUES ('122', 'aaa', '123', 'aaa@q.com', '1', '344444', '13248457', '4', '1,2,3', 'sfddsf', null, '0');
INSERT INTO `itcast_user` VALUES ('124', 'xiaoming', '1234', 'xiaoming@q.com', '3', '2973982', '23982789', '4', '1,3,4', 'I am xiaoming', null, '0');
INSERT INTO `itcast_user` VALUES ('125', 'daxiong', '900150983cd24fb0d6963f7d28e17f72', 'daxiong@q.com', '3', '9273982', '23927392', '5', '1,2,4', 'I am daxiong', null, '0');
INSERT INTO `itcast_user` VALUES ('126', 'xiaoli', 'caf1a3dfb505ffed0d024130f58c5cfa', 'xiaoli@q.com', '2', '234253', '2423432', '5', '1,3', 'I am xiaoli', '1387702517', '0');
INSERT INTO `itcast_user` VALUES ('127', 'qqqq', 'b59c67bf196a4758191e42f76670ceba', '', '1', '', '2332434', '4', '1,2', 'sdfsfs', '1387702814', '0');
INSERT INTO `itcast_user` VALUES ('128', 'tttt', '310dcbbf4cce62f762a2aaa148d556bd', 'ttt@q.com', '1', '2342543', '2432342', '3', '1,2,3', 'sdfsf', '1387703022', '0');
INSERT INTO `itcast_user` VALUES ('130', 'qqq', 'www', '', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('131', 'www', 'qqq', '', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('132', '', 'eeee', '', '1', '', '', '1', '', '', null, '0');
INSERT INTO `itcast_user` VALUES ('133', '123', '202cb962ac59075b964b07152d234b70', '123', '1', '123', '123', '2', '1,2,3', '123123', '1403066372', '1403066372');
INSERT INTO `itcast_user` VALUES ('134', 'qwe', '76d80224611fc919a5d54f0ff9fba446', 'qwe', '1', '123', '123', '4', '1,2', '123123', '1403066457', '1403066457');
INSERT INTO `itcast_user` VALUES ('135', 'asdfasdfadf', '12ef16e0d2c395d10cb4ded21aa1a799', 'asdfasdfadf', '1', '123', '123', '3', '1,2,3', '', '1403066538', '1403066538');
INSERT INTO `itcast_user` VALUES ('136', 'asdfasdfadf', 'd41d8cd98f00b204e9800998ecf8427e', 'asdfasdfadf', '1', '123', '123', '3', '1,2,3,4', '', '1403066609', '1403066609');
INSERT INTO `itcast_user` VALUES ('137', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin@itcast.com', '1', '123123123', '123123123', '3', '1,2,3,4', 'asdfadfasdf', '1403078160', '1403078160');
INSERT INTO `itcast_user` VALUES ('138', 'adsf', 'adfasd', 'adf', '1', 'asss', 'sdfsdf', '1', '', 'adsfasdf', null, '0');