1. 控制器=》 shopApplication/Admin/Controller/GoodsController.class.php
// $goodsModel = D('Goods'); //Admin/Model/GoodsModel
// $goodsModel = D('Home/Goods'); //Admin/Model/GoodsModel
// $studentModel = D('student'); //D()方法中的參數對應的模型可以不存在,使用基礎模型類創建對象,但是基礎模型類還是操作的是參數對應的表
// $model = D();
// $model->query('select * from itcast_goods'); //執行查詢類的sql
// $model->execute('delete|update|insert'); //執行修改類的sql
/* $goodsModel = D('Goods'); //如果根據Goods找不到對應的模型, 就直接調用M('Goods')方法
$goodsModel2 = M('Goods');
dump($goodsModel);
dump($goodsModel2);*/
// mysql_query('select *或者是字段 from 表名 where 條件 order by 列名 limit having');
// exit;
/*
$goodsModel->select();//查詢
$goodsModel->add();//添加
$goodsModel->save();//修改
$goodsModel->delete();//刪除.*/
$goodsModel = D('Goods');
$rows = $goodsModel->select();
// $goodsModel->field('goods_name,goods_price');
// $goodsModel->where('goods_price>1000 and goods_price<2000');
// $goodsModel->group('goods_category_id');
// $goodsModel->order('goods_category_id asc,goods_price desc');
// $goodsModel->limit(2,2);
// $rows = $goodsModel->field('goods_name')->order('goods_price')->where('goods_price>1000 and goods_price<2000')->limit(0,2)->select();
// $rows = $goodsModel->where("goods_id = %d","8")->select();
/* $goodsModel->count('*');
$goodsModel->max('goods_price');*/
// $goodsModel->find(9);
// $rows = $goodsModel->select();//select方法執行查詢出數據
// dump($rows);
// exit;
$this->assign('rows',$rows);
$this->display();
}
------------------**********---------------------************-------------------------
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/index.html
<!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 管理中心 - 商品管理 </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="brandAdd.html">添加貨品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - 商品 </span>
<div style="clear:both"></div>
</h1>
<div class="form-div">
<form action="" name="searchForm">
<img src="__IMG__/icon_search.gif" width="26" height="22" border="0" alt="search" />
<input type="text" name="brand_name" size="15" />
<input type="submit" value=" 搜索 " class="button" />
</form>
</div>
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
<table cellpadding="3" cellspacing="1">
<tr>
<th>商品名稱</th>
<th>商品價格</th>
<th>商品數量</th>
<th>添加時間</th>
<th>更新時間</th>
<th>操作</th>
</tr>
<volist name="rows" id="row" empty="沒有記錄">
<tr>
<td class="first-cell">
<span style="float:right">{$row.goods_name}</span>
</td>
<td align="center">{$row.goods_price}</td>
<td align="center">{$row.goods_number}</td>
<td align="center">{:date('Y-m-d H:i:s',$row['inputTime'])}</td>
<td align="center">2013-12-17 14:51</td>
<td align="center">
<a href="#" title="編輯">編輯</a> |
<a href="#" title="編輯">移除</a>
</td>
</tr>
</volist>
<tr>
<td align="right" nowrap="true" colspan="6">
<div id="turn-page">
總計 <span id="totalRecords">11</span>
個記錄分爲 <span id="totalPages">1</span>
頁當前第 <span id="pageCurrent">1</span>
頁,每頁 <input type='text' size='3' id='pageSize' value="15" />
<span id="page-link">
<a href="#">第一頁</a>
<a href="#">上一頁</a>
<a href="#">下一頁</a>
<a href="#">最末頁</a>
<select id="gotoPage">
<option value='1'>1</option>
</select>
</span>
</div>
</td>
</tr>
</table>
</div>
</form>
<div id="footer">
共執行 3 個查詢,用時 0.021251 秒,Gzip 已禁用,內存佔用 2.194 MB<br />
版權所有 © 2005-2012 上海商派網絡科技有限公司,並保留所有權利。</div>
</body>
</html>
------------------------------*************-----------------------------***************---------------
4.效果顯示圖 :