使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(六)表白页面

这个页面相对于其他页面来说比较复杂,涉及到写入数据库

1.页面控制器

Mobile/Controller/SayloveController.class.php

<?php
	namespace Mobile\Controller;
	use Think\Controller;
	class SayloveController extends Controller{
		public function index(){
			$this->display();
		}
		
		public function addSayLove(){
			//添加表白

			//获取数据
			$data = array(
				'title' => I("post.saylove"),
				'time' =>time() ,
				'IP' => get_client_ip(), 
				'user_name' =>I('post.username'),
				'type' =>3,//3->待审|2->未过|1->通过
				);
		//实例化模型
			$SayLove = D('saylove');
			//创建数据对象
			if($SayLove->create($data)) {
	            	//将数据写入数据库
	            $result =  $SayLove -> add();
	       			
	       			if($result) {
	       	       			$this->success('发布表白成功,等待审核!','../wall');
	        	    }else{
	            		    $this->error('数据添加错误!');
	            	}
	        }else{
	        	$this->error($SayLove->getError());
	        }
		}

	}
thinkphp乃至PHP的数据库操作都很简洁

2.需要进行 数据验证过滤,终于用到Model了

Mobile/Model/SayloveController.class.php

<?php
namespace Mobile\Model;
use Think\Model;
class SayloveModel extends Model{
    protected $_validate = array(
        array('title','require','请填写内容!'), //默认情况下用正则进行验证
        array('use_name','require','请填写昵称!'), //默认情况下用正则进行验证
        array('title', '3,10', '长度必须在3-30位之间!', 0, 'length'),
        array('user_name', '1,10', '昵称长度必须在1-10位之间!', 0, 'length'),
    );
}
效果图:

使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(六)表白页面_第1张图片

3.VIew层

Mobile/View/Saylove/index.html

<include file="Public:header"/>
<h3 class="page_title">Say-Love</h3>
<p class="page_desc">有爱大声说出来</p>
   <div class="weui_cells_title">表白话语</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <form action="{:U('Saylove/addSayLove')}" method="post" role="form" >
                    <textarea class="weui_textarea" placeholder="30字足以表达你的爱" rows="3" name="saylove"></textarea>
                    <div class="weui_textarea_counter"><span>0</span>/30</div>
                </div>
            </div>
        </div>

           <div class="weui_cells_title">昵称</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <textarea name="username" class="weui_textarea" placeholder="既然敢爱就要敢当" rows="1"></textarea>
                    <div class="weui_textarea_counter"><span>0</span>/10</div>
                </div>
            </div>
        </div>

          <p class="weui_btn_area">
                         <button href="javascript:;" class="weui_btn weui_btn_plain_primary" type="submit">确定</button>
           </p>
          
         
     
       </form>
<include file="Public:footer"/>
使用微信的开源前端weui,数据是表单提交

效果图:

使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(六)表白页面_第2张图片

吐槽下:没域名、没备案的会被微信拦截,而且一个链接一个页面一次拦截

在火狐浏览器效果最佳

个体开发者也很不容易,需要耐心折腾

你可能感兴趣的:(thinkphp)