zoukankan      html  css  js  c++  java
  • Thinkphp交友手机首页简明前台、后台

    先来说下后台吧,后台要写后台模板-V,后台控制器-C

    后台模板如下代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    </head>
    <body>
    
        <div>
            <form action="__URL__/add_img" enctype="multipart/form-data" method="post" style="padding:10px;" >
                图片宽:<input type="text" name="width" style="60px " />
                图片长:<input type="text" name="height" style="60px " />
                <input type="file" name="photo" style="150px "/>
                <input type="submit" value="上传" >
            </form>
        
        </div>
        <table  width="400" border="1" style="padding:2px;  margin-left:10px;">
                <tr>
                        <td align="center">ID</td>
                        <td align="center">照片</td>
                        <td align="center" >大小</td>
                        <td align="center">操作</td>
                        
                </tr>
            <foreach name="list" item="vo">
                <tr>
                    <td align="center">{$vo.id}</td>
                    <td  align="center"><img src="http://www.hnb.cc{$vo.photo}" alt=""  style="35px;height:25px;"></td>
                    <td align="center">{$vo.size}</td>
                    <td align="center" ><a href="{:U('admin/vip/del',array('id'=>$vo[id] ))}" >删除</a></td>
                  
                </tr>
            </foreach>
        </table>
        <div>{$page}</div>
    
    </body>
    </html>

    然后是后台控制器代码如下:

    <?php 
    /*功能:手机首页后台设置*/
    class VipAction extends CommonAction 
    {
        /*后台首页显示*/
       public function index()
       {
               $moden=M('wap_photo');
            /*分页*/
            import("ORG.Util.Page");// 导入分页类
            $count= $moden->count();// 查询满足要求的总记录数
            $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
            $show= $Page->show();// 分页显示输出
            $rs=$moden->field("id,photo,size")->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();
            $this->assign('page',$show);// 赋值分页输出
            /*分页结束*/
            $this->assign('list',$rs);
            $this->display();
        }
       //后台删除表中的数据、删除文件待更新
        public function del()
        {
            if($_GET)
            {
                // print_r($_GET);exit;
                $id=$_GET['id'];
                $moden=M('wap_photo');
                $rs=$moden->where("id=$id")->delete();
                if($rs)
                {
                    $this->success('删除成功');
                }
            }
    
        }
        /*hnb图片上传函数*/
        function add_img()
        {
            if($_POST['width']&&$_POST['height'])
            {
                $rs=import('ORG.Net.UploadFile');
                $upload=new UploadFile();
                $upload->maxSize=2097153;  //设置上传文件大小为2M
                $root_path=BATH_PATH;       //等下好上传
                $sub_path='/image/wapphoto/';//一切为了上传
                $upload->savePath =BATH_PATH .'/image/wapphoto/';// 设置附件上传目录
                $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->thumb = true;
                $upload->thumbMaxWidth = $_POST['width'];
                $upload->thumbMaxHeight = $_POST['height'];
                $file->thumbPath=BATH_PATH .'/image/wapphoto/';//缩略图保存路径
                $upload->thumbRemoveOrigin=true;//生成缩略图是否删除原图片
                if(!$upload->upload()) 
                {// 上传错误提示错误信息
    
                    $this->error($upload->getErrorMsg());
    
                }else{// 上传成功 获取上传文件信息
    
                    $info =  $upload->getUploadFileInfo();
                    $model=M('wap_photo');
                    $model->photo=$sub_path.'thumb_'. $info[0]["savename"]; 
                    $model->size=$_POST['width'].'*'.$_POST['height'];
                    $model->time=time();
                    $model->add();
                    $this->success("数据保存成功!");
                }
    
            }else
            {
                echo '上传失败';
                return false;
            }
        }
    }
    
     ?>

    前台代码比较多,要写控制器,要写moden,还要写view

    下面是前台主入口文件代码:因为前台是放在另一个网站目录下的

    <?php
    /**
     * [OELove] (C)2012-2099 OEdev,Inc.
     * <E-Mail:phpcoo@phpcoo.com>
     * Url http://www.phpcoo.com
     *     http://www.oemarry.com
     *     http://www.oedev.net
     * Update 2013.09.09
    */
    //载入主文件
    require_once 'source/core/run.php';
    require_once 'source/core/util/function.iswap.php';
    if (false == mobile_device_detect()) {
       // XHandle::redirect(PATH_URL.'index.php');
    }
    //c&a参数
    $c = XRequest::getGpc('c');
    $a = XRequest::getGpc('a');
    $c = empty($c) ? 'vip' : $c;
    $a = empty($a) ? 'run' : $a;
    //Controller
    if (!in_array($c, 
        array(
            'index', 'passport', 'about', 'user', 'home', 'online', 'vip',
            'cp', 'cp_do', 'cp_info', 'cp_message', 'cp_visit', 
            'cp_listen', 'cp_fans', 'cp_money', 'cp_points', 'cp_photo', 'party', 
        ))) {
        XHandle::error('Wap Controller ['.$c.'] is forbiden!');
    }
    $control_base = BASE_ROOT.'./source/control/wapbase.php';
    $hook_base = BASE_ROOT.'./source/control/apphook.php';
    $control_path = BASE_ROOT.'./source/control/wap/'.$c.'.php';
    if (!file_exists($control_path)) {
        XHandle::error('Wap Controller file:['.$c.'] is not found!');
    }
    else {
        require_once($control_base);
        require_once($hook_base);
        require_once($control_path);
        $control = new control();
        $method = 'control_'.$a;
        if (method_exists($control, $method) && $a{0} != '_') {
            $control->$method();
        } 
        else {
            XHandle::error('Wap Controller ['.$c.'] Action ['.$a.'] is not found!');
        }
        unset($control);
    }
    ?>

    前台控制器

    主要作用是调用model 把变量,跟模板输出

    代码如下:

    <?php
    /*********************/
    /*                   */
    /*  Version : 5.1.0  */
    /*  Author  : RM     */
    /*  Comment : 071223 */
    /*                   */
    /*********************/
    
    if ( !defined( "IN_OESOFT" ) )
    {
        exit( "Access Denied" );
    }
    class control extends wapbase
    {
        private $service = NULL;
        private $_tplfile = NULL;
        /*这种写法才能assign    
            $this->getMeta( "ch_index" );
            $var_array = array(
                            "page_title" => $this->metawrap['title'],
                            "page_description" => $this->metawrap['description'],
                            "page_keyword" => $this->metawrap['keyword']
            );
            TPL::assign( $var_array );
        */
        /*hnb调用moden取出数据,并输出在模板*/
        public function control_run( )
        {
            $model = parent::model('vip', 'wm');
            $vip_data=$model->getPhoto();
            /*把取出来的数据排顺序*/
            $var_array = array("vip_data" => $vip_data);
            TPL::assign($var_array);
            $this->_tplfile = $this->getTPLFile( "vip" );
            TPL::display( $this->_tplfile );
        }
    }
    ?>

    moden 代码如下:主要是调用数据库,取数据,并把取出的数据再排列

    <?php
    if ( !defined( "IN_OESOFT" ) )
     {
        exit( "Access Denied" );
    }
    
    class vipWModel extends X 
    {
        /*hnb取照片出来并排列*/
        public function getPhoto()
        {
            $dbname='7799520';
            $model=parent::$obj->select_db($dbname);
            // $sql="select id, isShow,photo,tagID from reg_photo where isShow='1' order by rand() limit 10";
            $size='245*189';
            $sql="select id,photo,size from wap_photo where size='$size' limit 4";
            $model_one = parent::$obj->getall($sql);
            $model_one_sub=array_splice($model_one, 2);
            $sql="select id,photo,size from wap_photo where size<>'$size' limit 6";
            $model_two=parent::$obj->getall($sql);
            $model_two_sub=array_splice($model_two, 3);
            $model=array_merge($model_one,$model_two,$model_one_sub,$model_two_sub);
            $web_path="http://www.hnb.cc";
            if($model)
            {
                $data=array();
                foreach ($model as $k=>$v) 
                {
                    $data[]=$web_path . $v['photo'];
                } 
            }
            return $data;
         }
    }
    ?>

    最后是前台的模板代码vip.tpl

    代码如下:

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta charset="UTF-8">
    <title>我主良缘一对一服务</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    
    <script src="<!--{$wapskin}-->js/ipinfo.jsp" type="text/javascript"></script>
    <script src="<!--{$wapskin}-->js/jquery.js"></script>
    <script language="javascript" src="<!--{$wapskin}-->js/serivcearea.js"></script>
    <link rel="stylesheet" type="text/css" href="<!--{$wapskin}-->style/vip.css" media="all">
    
    </head>
    <body>
        <div class="head">
            <div class="btn-box">
                <a href="<!--{$wapfile}-->?c=passport&a=reg" class="signup">免费注册</a>
                <a href="<!--{$wapfile}-->?c=passport&a=login" class="login">登    录</a> 
             </div>
        </div>
        <div class="banner">
            <img src="<!--{$wapskin}-->images/xj/01.png">
        </div>
    
       
        <div class="content fn-clear">
            <!--{foreach $vip_data as $key=>$volist}-->
                <!--{if $key==0 ||$key==1||$key==5||$key==6}-->
                     <div class="imgbox imgbox1" onclick="window.location.href='<!--{$wapfile}-->?c=passport&a=login'">
                    <img src="<!--{$volist}-->"><span>约见TA</span> </div>
                <!--{else}--> 
                     <div class="imgbox imgbox2" onclick="window.location.href='<!--{$wapfile}-->?c=passport&a=login'">
                    <img src="<!--{$volist}-->"><span>约见TA</span> </div>
                <!--{/if}--> 
            <!--{/foreach}-->
    
        </div>
    
        <div class="banner">
            <img src="<!--{$wapskin}-->images/xj/02.png">
        </div>
       
        <nav>
       
            <ul class="fn-clear">
                <li><a class="phone" href="tel:400-7799520">电话咨询</a></li>
                <li><a class="liuyan" href="http://webim.qiao.baidu.com//im/index?siteid=6789020&ucid=2774470&qq-pf-to=pcqq.c2c" >在线咨询</a></li>
                <li><a class="fuwu" href="http://www.7799520.com/activities/" >各地活动</a></li>
                <li><a class="shenqing" href="#">各地公司</a></li>
            </ul>
        </nav>
        
    <div id="footer" class="foot">我主良缘一对一服务<br></div>
    <script>
        $(function(){
            var userId=12;
            var isLogin=0;
            if(!isLogin){
                $(".login").show();
                $(".signup").show();
                $(".apply").hide();    
            }else{
                $(".login").hide();
                $(".signup").hide();
                $(".apply").show();    
            }
            
        });
    
    
    </script>
    
    
    </body>
    </html>

    当然还有数据库表如下:

    SET FOREIGN_KEY_CHECKS=0;

    -- ----------------------------
    -- Table structure for wap_photo
    -- ----------------------------
    DROP TABLE IF EXISTS `wap_photo`;
    CREATE TABLE `wap_photo` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `photo` varchar(80) NOT NULL DEFAULT '',
      `size` varchar(15) NOT NULL DEFAULT '',
      `time` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=36 DEFAULT CHARSET=utf8;


    INSERT INTO `wap_photo` VALUES ('1', '/image/wapphoto/54befd120ad22.png', '245*189', '0');
    INSERT INTO `wap_photo` VALUES ('2', '/image/wapphoto/54bf38654d328.png', '245*189', '0');
    INSERT INTO `wap_photo` VALUES ('3', '/image/wapphoto/54bf415b4d40f.png', '0', '0');
    INSERT INTO `wap_photo` VALUES ('4', '/image/wapphoto/54bcdda252076.png', '0', '0');
    INSERT INTO `wap_photo` VALUES ('5', '/image/wapphoto/54bf37a9dac98.png', '0', '0');
    INSERT INTO `wap_photo` VALUES ('7', '/image/wapphoto/54bf392c70fe5.png', '245*189', '0');
    INSERT INTO `wap_photo` VALUES ('8', '/image/wapphoto/54bf42af6e3c6.png', '245*189', '0');
    INSERT INTO `wap_photo` VALUES ('9', '/image/wapphoto/5554607d2cee3.png', '0', '0');
    INSERT INTO `wap_photo` VALUES ('10', '/image/wapphoto/5554620071e15.png', '0', '0');
    INSERT INTO `wap_photo` VALUES ('11', '/image/wapphoto/553745ff8902c.png', '0', '0');

  • 相关阅读:
    Command模式应用实践
    .Net中的设计模式——Strategy模式
    PetShop之ASP.NET缓存
    征求书名
    PetShop之业务逻辑层设计
    Buider模式应用实践
    公告:目前博客园书业出版小组的工作进度
    “AS3.0高级动画编程”学习:第二章转向行为(下)
    as3: this,stage,root的测试
    As3.0中的位图(Bitmap/BitmapData)编程
  • 原文地址:https://www.cnblogs.com/hnbiao/p/4551741.html
Copyright © 2011-2022 走看看