<?php
namespace Admin\Controller;
namespace Admin\Controller;
use \Think\Controller;
class GoodsController extends Controller {
protected $model = null;
class GoodsController extends Controller {
protected $model = null;
public function __construct() {
parent::__construct();
parent::__construct();
$this->model = D('Home/Goods');
}
}
_______________________________________________________________________________
<form enctype="multipart/form-data" action="" method="post" name="theForm" >
<tr>
<td class="label">上传商品图片:</td>
<td>
<input type="file" name="goods_img" size="35" />
</td>
</tr>
<td class="label">上传商品图片:</td>
<td>
<input type="file" name="goods_img" size="35" />
</td>
</tr>
———————————————————————————————————————————————————————————————————————————————
public function add() {
if(!IS_POST) {
$this->display();
} else {
//echo $this->model->add($_POST) ? 'OK' : 'fail';
if(!IS_POST) {
$this->display();
} else {
//echo $this->model->add($_POST) ? 'OK' : 'fail';
// create()会把参数, 赋给内部的data,(如果没传参,则把$_POST赋给内部data)
// create()的赋值过程,会检测数据的合法性, 自动验证将会发挥作用
if(!$this->model->create()) {
echo $this->model->getError();
} else {
if(isset($_FILES['goods_img'])) { //判断是不是有图片先
$up = new \Think\Upload();
$up->exts = array('jpeg' , 'jpg' , 'png' , 'gif');
$up->rootPath = APP_PATH;
$up->savePath = '/Public/images/';
// create()的赋值过程,会检测数据的合法性, 自动验证将会发挥作用
if(!$this->model->create()) {
echo $this->model->getError();
} else {
if(isset($_FILES['goods_img'])) { //判断是不是有图片先
$up = new \Think\Upload();
$up->exts = array('jpeg' , 'jpg' , 'png' , 'gif');
$up->rootPath = APP_PATH;
$up->savePath = '/Public/images/';
$info = $up->upload();
if($info) {
//savename 默认unique 自动生成一个//
$this->model->ori_img = $info['goods_img']['savepath'] . $info['goods_img']['savename'];
$this->model->goods_img = $this->model->ori_img . '230X230.png';
$this->model->thumb_img = $this->model->ori_img . '100X100.png';
if($info) {
//savename 默认unique 自动生成一个//
$this->model->ori_img = $info['goods_img']['savepath'] . $info['goods_img']['savename'];
$this->model->goods_img = $this->model->ori_img . '230X230.png';
$this->model->thumb_img = $this->model->ori_img . '100X100.png';
//作用将图片的地址保存在数据库里 相对应的字段上
//以便将来取出数据使用
//以便将来取出数据使用
-————————————————————————————————————————————————————————————————————————————
缩 略 图 //
缩 略 图 //
// 缩略
$img = new \Think\Image();
//先打开图片再进行操作 $img->open(APP_PATH . $this->model->ori_img);
//thumb 缩放 前两个参数 宽高 最后一个参数 缩略样式
// 缩略样式 \Think\Image::IMAGE_THUMB_FILLED 两端留白
$img->thumb(230,230,\Think\Image::IMAGE_THUMB_FILLED);
$img->save(APP_PATH . $this->model->goods_img);
$img = new \Think\Image();
//先打开图片再进行操作 $img->open(APP_PATH . $this->model->ori_img);
//thumb 缩放 前两个参数 宽高 最后一个参数 缩略样式
// 缩略样式 \Think\Image::IMAGE_THUMB_FILLED 两端留白
$img->thumb(230,230,\Think\Image::IMAGE_THUMB_FILLED);
$img->save(APP_PATH . $this->model->goods_img);
$img->thumb(100,100,\Think\Image::IMAGE_THUMB_FILLED);
$img->save(APP_PATH . $this->model->thumb_img);
}
}
$this->model->goods_desc = $_POST['goods_desc'];
echo $this->model->add() ? 'OK' : 'fail';
}
}
}
$img->save(APP_PATH . $this->model->thumb_img);
}
}
$this->model->goods_desc = $_POST['goods_desc'];
echo $this->model->add() ? 'OK' : 'fail';
}
}
}
/分 页 类 ///
public function lists() {
public function lists() {
//数一下 每页有多少条?
$cnt = $this->model->count('*'); // select count(*) from goods;
$cnt = $this->model->count('*'); // select count(*) from goods;
//自己写一个分页类?继承一下放在那里?? libery /org /A/B.class.php下
$page = new \Org\A\B($cnt,2); // 分布类初始化成功
$pages = $page->show(); 计算书分页代码了
$page = new \Org\A\B($cnt,2); // 分布类初始化成功
$pages = $page->show(); 计算书分页代码了
$this->model->field('goods_id,goods_name,goods_sn,shop_price,is_best,is_new,is_hot');
$this->model->order('goods_id desc')->limit($page->firstRow,$page->listRows);
//不同的页码的限制limit 页数 条数不同 limit $page->firstRow $page->kistRows
//自己写一个分页类?继承一下放在那里?? libery /org /XX/XX下
$this->model->order('goods_id desc')->limit($page->firstRow,$page->listRows);
//不同的页码的限制limit 页数 条数不同 limit $page->firstRow $page->kistRows
//自己写一个分页类?继承一下放在那里?? libery /org /XX/XX下
$goods = $this->model->select();
$this->assign('pages' , $pages);
$this->assign('goods' , $goods);
$this->display();
}
$this->assign('goods' , $goods);
$this->display();
}
public function del() {
$this->model->delete(I('get.goods_id'));
$this->model->delete(I('get.goods_id'));
$this->redirect('Admin/Goods/lists');
}
}
}
}
——————————————————————————————————————————————————————————————————————————————
------------------------------------------------------------------------------
验证码
$cf = array(
'fontSize'=> 30 ,
'useNoise'=>false ,
'length'=>5,
);
------------------------------------------------------------------------------
验证码
$cf = array(
'fontSize'=> 30 ,
'useNoise'=>false ,
'length'=>5,
);
$vfy = nw Think\Verify($cf);
$vfy->entry();
$vfy->entry();
------------------------------------------------------------------------------
$vfy = new Think\Verify();
$vfy->length = 5;
$vfy->fontSize = 20;
$vfy -> useNoise =false ;
$vfy->entry();
$vfy->length = 5;
$vfy->fontSize = 20;
$vfy -> useNoise =false ;
$vfy->entry();
-------------------------------------------------------------------------------
$up = new Think\Upload();
$up->exts=array();
$up-> rootPath = APP_PATH;
$up->savePath = '/Public/Img/';
$info = $up->save();
$up-> rootPath = APP_PATH;
$up->savePath = '/Public/Img/';
$info = $up->save();
if($info){
$this->model->org_img = $info['img']['rootPath'] . $info['img']['savename'];
$this->model->goods_img =$this->model->org_img . '100X100.png'
$this->model->thumb_img =$this->model->org_img . '300X300.png'
$this->model->org_img = $info['img']['rootPath'] . $info['img']['savename'];
$this->model->goods_img =$this->model->org_img . '100X100.png'
$this->model->thumb_img =$this->model->org_img . '300X300.png'
//缩略图
$img = new Think\Image();
$img->open(APP_PATH . $this->model->Org_img);
$img->open(APP_PATH . $this->model->Org_img);
$img->thumb(100, 100 , ....);
$img->save($this->model->thumb_img );
$img->save($this->model->thumb_img );
$img ->thumb (300,300, ....);
$img->save($this ->model ->gods_img);
$img->save($this ->model ->gods_img);
}
$this->model ->add();
_______________________________________________________________________________