20181101 完整的tp
目录
入口文件 index.PHP代码
<?php //调试 define('APP_DEBUG',true);//调试模式 define("UPLOAD_PATH","http://localhost/myTP/app/upload/");//配置常量 // 定义应用目录 define("APP_PATH","./app/"); // 引入ThinkPHP入口文件 include("ThinkPHP/ThinkPHP.php");
Admin/view/Users/zhuce.html 代码
<!doctype html> <html> <head> <meta charset="utf-8"> <title>注册页面</title> </head> <body> <form action="__SELF__" method="post"> 账号:<input type="text" name="user_id"><br> 密码:<input type="password" name="password"><br> qq:<input type="text" name="qq"><br> email:<input type="text" name="email"><br> <button type="submit">注册</button> </form> </body> </html>
Admin/view/Manager/index.html 代码(就只写一个首页的代码)
<!doctype html public "-//w3c//dtd xhtml 1.0 frameset//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-frameset.dtd"> <html> <head> <meta http-equiv=content-type content="text/html; charset=utf-8" /> <meta http-equiv=pragma content=no-cache /> <meta http-equiv=cache-control content=no-cache /> <meta http-equiv=expires content=-1000 /> <title>管理中心 v1.0</title> </head> <frameset border=0 framespacing=0 rows="60, *" frameborder=0> <frame name=head src="__URL__/head" frameborder=0 noresize scrolling=no> <frameset cols="170, *"> <frame name=left src="__URL__/left" frameborder=0 noresize /> <frame name=main src="__URL__/right" frameborder=0 noresize scrolling=yes /> </frameset> </frameset> <noframes> </noframes> </html>
Admin/view/Login/login.html 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta content="MSHTML 6.00.6000.16674" name="GENERATOR" /> <title>用户登录</title> <link href="__CSS__/User_Login.css" type="text/css" rel="stylesheet" /> </head><body id="userlogin_body"> <div></div> <div id="user_login"> <dl> <dd id="user_top"> <ul> <li class="user_top_l"></li> <li class="user_top_c"></li> <li class="user_top_r"></li></ul> </dd><dd id="user_main"> <form action="__URL__/check" method="post"> <ul> <li class="user_main_l"></li> <li class="user_main_c"> <div class="user_main_box"> <ul> <li class="user_main_text">用户名: </li> <li class="user_main_input"> <input class="TxtUserNameCssClass" id="admin_user" maxlength="20" name="admin_user"> </li> </ul> <ul> <li class="user_main_text">密 码: </li> <li class="user_main_input"> <input class="TxtPasswordCssClass" id="admin_psd" name="admin_psd" type="password"> </li> </ul> <ul> <li class="user_main_text">验证码: </li> <li class="user_main_input"> <input class="TxtValidateCodeCssClass" id="captcha" name="captcha" type="text"> <img src="__URL__/yzm" onClick="this.src='__URL__/yzm/'+Math.random()" /> </li> </ul> </div> </li> <li class="user_main_r"> <input style="border: medium none; background: url('__IMG__/user_botton.gif') repeat-x scroll left top transparent; height: 122px; width: 111px; display: block; cursor: pointer;" value="" type="submit"> </li> </ul> </form> </dd><dd id="user_bottom"> <ul> <li class="user_bottom_l"></li> <li class="user_bottom_c"><span style="margin-top: 40px;"></span> </li> <li class="user_bottom_r"></li></ul></dd></dl></div><span id="ValrUserName" style="display: none; color: red;"></span><span id="ValrPassword" style="display: none; color: red;"></span><span id="ValrValidateCode" style="display: none; color: red;"></span> <div id="ValidationSummary1" style="display: none; color: red;"></div> </body> </html>
Admin/view/Goods/zhanshi.html 代码(就只写一个展示的代码)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>会员列表</title> <link href="__CSS__/mine.css" type="text/css" rel="stylesheet" /> </head> <body> <style> .tr_color{background-color: #9F88FF} </style> <div class="div_head"> <span> <span style="float: left;">当前位置是:商品管理-》商品列表</span> <span style="float: right; margin-right: 8px; font-weight: bold;"> <a style="text-decoration: none;" href="__URL__/add">【添加商品】</a> </span> </span> </div> <div></div> <div class="div_search"> <span> <form action="#" method="get"> 品牌<select name="s_product_mark" style="width: 100px;"> <option selected="selected" value="0">请选择</option> <option value="1">苹果apple</option> </select> <input value="查询" type="submit" /> </form> </span> </div> <div style="font-size: 13px; margin: 10px 5px;"> <table class="table_a" border="1" width="100%"> <tbody><tr style="font-weight: bold;"> <td width="10">序号</td> <td width="20">商品名称</td> <td width="10">库存</td> <td width="10">价格</td> <td width="10">图片</td> <td width="10">缩略图</td> <td width="10">品牌</td> <td width="10">创建时间</td> <td width="10" align="center">操作</td> </tr> <volist name="list" id="vo"> <tr id="product{$i}"> <td>{$vo.goods_id}</td> <td><a href="#">{$vo.goods_name}</a></td> <td>{$vo.store_count}</td> <td>{$vo.shop_price}</td> <td><img src=" {$Think.const.UPLOAD_PATH}{$vo.original_img}" height="60" width="60"></td> <td><img src="{$Think.const.UPLOAD_PATH}{$vo.keywords}" height="40" width="40"></td> <td> {$brandlist[$vo["brand_id"]]["name"]} </td> <td>{$vo.on_time|date="Y-m-d H:m:s",###}</td> <td><a href="__URL__/update/id/{$vo.goods_id}">修改</a> <a href="__URL__/del/id/{$vo.goods_id}">删除</a> </td> </tr> </volist> <tr> <td colspan="20" style="text-align: center;"> {$page} </td> </tr> </tbody> </table> </div> </body> </html>
Admin/public (里面是公用的img css)
Admin/Model/ UsersModel.class.PHP 代码
<?php namespace Admin\Model; use Think\Model; //Admin模块的manager控制器 class UsersModel extends Model{ // 是否批处理验证 protected $patchValidate = true; //自动验证 protected $_validate = array( //array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]), array('user_id','require','账号必须写!'), //默认情况下用正则进行验证 array('password','require','密码必须写!'), //默认情况下用正则进行验证 array('email','email','邮箱格式错误'), //默认情况下用正则进行验证 array('user_qq','5,12','qq号码位数5到12之间',0,'length') ); //自动完成 protected $_auto = array ( array('reg_time','time',3,'funtion'), // 对name字段在新增和编辑的时候回调getName方法 ); }
Admin/Model/ GoodsModel.class.PHP 代码
<?php namespace Admin\Model; use Think\Model; class GoodsModel extends Model{ protected $_auto=array( array("on_time","time",3,"function") ); }
Admin/Controller/ UsersController.class.PHP 代码
<?php namespace Admin\Controller;//声明 use Think\Controller;//用Controller在什么位置 //Admin模块的manager控制器 class UsersController extends Controller{ function zhuce(){ echo " <meta http-equiv='content-type' content='text/html; charset=UTF-8' />"; if(IS_POST){ $user=D("users");//创建模型 $user->create();//收集表单 var_dump($user->getError()); die();//提示验证错误 } $this->display(); } }
Admin/Controller/ ManagerController.class.PHP 代码
<?php namespace Admin\Controller;//声明 use Think\Controller;//用Controller在什么位置 //Admin模块的manager控制器 class ManagerController extends Controller{ function index(){ $this->display();//调用模板 } function left(){ $this->display();//调用模板 } function right(){ $this->display();//调用模板 } function head(){ $this->display();//调用模板 } function _empty(){ echo"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>"; echo"控制器不存在"; } function show404page(){ echo"404"; } }
Admin/Controller/ LoginController.class.PHP 代码
<?php namespace Admin\Controller;//声明 use Think\Controller;//用Controller在什么位置 use Think\Verify;//用Controller在什么位置 //Admin模块的login控制器 class LoginController extends Controller{ function login(){ $this->display();//调用模板 } //登录验证 function check(){ echo"<meta http-equiv=content-type content='text/html; charset=utf-8' />"; $uid=$_POST["admin_user"]; $pwd=$_POST["admin_psd"]; $captcha=$_POST["captcha"]; $yzm=new Verify(); if(!$yzm->check($captcha)){ $this->error("登录失败",U("login"),2); } $data=M("users")->select($uid); if($pwd==$data[0]["password"]&&$pwd !=""){ //跳转的地址 跳转的传递参数 停留时间 显示的消息 $this->redirect("Manager/index",array(),3,"登录成功"); }else{ $this->error("验证失败",U("login"),2); } } //验证码 function yzm(){ $config=array( 'imageH' => 25, // 验证码图片高度 'imageW' => 100, // 验证码图片宽度 'length' => 4, // 验证码位数 'fontSize' => 14, // 验证码位数 'fontttf' => '4.ttf', // 验证码字体 ); $yzm=new Verify($config); $yzm->entry(); } //查看配置信息 function test1(){ echo C("PHP"); } function test2(){ $this->display();//调用模板 } //连接数据库 function test3(){ $Goods=M("student"); $list=$Goods->select();//查询数据 $this->assign('aa',$list);//注册视图 $this->display();//显示视图 } function test4(){ $G=M("student"); $data=array( "sno"=>"110", "sname"=>"宋平220" ); // echo $G->add($data);//增加数据 // echo $G->save($data);//更新数据 echo $G->delete(110);//删除数据 } }
Admin/Controller/ GoodsController.class.PHP 代码
<?php namespace Admin\Controller;//声明 use Think\Controller;//用Controller在什么位置 use Think\Page; use Think\Upload; //Admin模块的login控制器 class GoodsController extends Controller{ //显示的方法 function zhanshi(){ $goods=M('goods'); //实现数据分页效果 //① 获得记录总条数 $total = $goods -> count(); $per = 7; //② 实例化分页类对象 $page = new \Tools\Page($total, $per); //③ 拼装sql语句获得每页数据信息 // 执行原生sql语句 // 查询:model->query() 二维数组返回记录信息 // 添加、修改、删除:model->execute() 受影响的记录条数 $sql = "select * from tp_goods order by goods_id asc ".$page->limit; $list = $goods -> query($sql);//执行原生sql语句,返回二维数组信息 //④ 获得页码列表 $pageStr = $page -> fpage(); $brand=M("brand"); $brandlist=$brand->select();//查表 $brr=array(); foreach($brandlist as $v){ $brr[$v['id']] = $v; } $this->assign("brandlist",$brr); $this->assign('list',$list); $this->assign('page',$pageStr); $this->display(); } //增加的方法 function add(){ if(IS_POST){ $goods=D('goods');//找到表 $data=$goods->create(); //使用上传文件类 $conf=array( "rootPath"=>"./app/upload/" ); $up=new Upload($conf); $info=$up->uploadOne($_FILES["original_img"]); $data["original_img"]=$info["savepath"].$info["savename"]; //创建缩略图 $img=new \Think\Image(); $big_img=$up->rootPath.$info["savepath"].$info["savename"]; $img->open($big_img);//打开大图 $img->thumb(120,120,6);//生成缩略图 $img->save($up->rootPath.$info["savepath"]."small".$info["savename"]); $data["keywords"]=$info["savepath"]."small".$info["savename"]; $msg="添加失败"; $url="add"; if($goods->add($data)){ $msg="添加成功"; $url="zhanshi"; } $this->redirect($url,array(),1,$msg); } $type=M('goods_type'); $typelist=$type->select();//查类型表 $brand=M("brand"); $brandlist=$brand->select();//查品牌表 $this->assign('typelist',$typelist);//zhuce $this->assign('brandlist',$brandlist); $this->display(); } //修改的方法 function update($id){ if(IS_POST){ $goods=M('goods');//找到表 $data=$goods->create(); //使用上传文件类 $conf=array( "rootPath"=>"./app/upload/" ); $up=new Upload($conf); $info=$up->uploadOne($_FILES["original_img"]); $data["original_img"]=$info["savepath"].$info["savename"]; if($goods->save($data)){ $this->success("修改成功",U("zhanshi"),2); }else{ $this->error("修改失败",U("zhanshi"),2); } die; } $goods=M('goods'); $data=$goods->select($id); $type=M('goods_type'); $typelist=$type->select();//查类型表 $brand=M("brand"); $brandlist=$brand->select();//查品牌表 $this->assign('typelist',$typelist);//zhuce $this->assign('brandlist',$brandlist); $this->assign('arr',$data[0]);//zhuce $this->display(); } //删除的方法 function del( $id){//参数的键名叫id $goods=M('goods'); if($goods->delete($id)){ $this->success("删除成功",U("zhanshi"),2); }else{ $this->error("删除失败",U("zhanshi"),2); } } }
Admin/Controller/ EmptyController.class.PHP 代码
<?php //空控制器 namespace Admin\Controller;//声明 use Think\Controller;//用Controller在什么位置 //Admin模块的manager控制器 class EmptyController extends Controller{ //空操作 function _empty(){ echo"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>"; echo"方法不存在"; } }
Admin/Conf/ config.PHP 代码
<?php return array( //'配置项'=>'配置值' 'TMPL_PARSE_STRING'=>array( "__CSS__" => __ROOT__."/app/Admin/Public/css", "__IMG__" => __ROOT__."/app/Admin/Public/img" ), );
转载请写明出处!!!!!!
D:\wampserver\wamp\www\myTP