tp 表单

<h1>用户添加页面</h1>
<form action="useradd" method="post" enctype="multipart/form-data">
    {:token('__token__', 'sha1')}
    <p>姓名:<input type="text" name="name"></p>
    <p>电话:<input type="tel" name="phone"></p>
    <p>邮箱:<input type="email" name="email"></p>
    <p>性别:
        <input type="radio" name="sex" value="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        <input type="radio" name="sex" value="2"></p>
    <p>爱好:
        <input type="checkbox" name="hobby[]" value="旅游">旅游
        <input type="checkbox" name="hobby[]" value="游泳">游泳
        <input type="checkbox" name="hobby[]" value="唱歌">唱歌
        <input type="checkbox" name="hobby[]" value="跑步">跑步
    </p>
    <p>头像:<input type="file" name="img"></p>
    <p>简介:<textarea name="introduce"></textarea></p>
    <p>生日:<input type="date" name="u_day"></p>
    <p>城市:<input type="text" name="city"></p>
    <p>验证码:<input type="text" name="code"></p>
    <div><img src="{:captcha_src()}" alt="captcha" /></div>
    <input type="submit" value="提交">
</form>
<?php

namespace app\admin\controller;

use app\admin\model\Secondary;
use think\App;
use think\captcha\Captcha;
use think\Controller;
use think\Request;

class UserTo extends Controller
{
    protected $request;
    protected $userto;

    public function __construct(Request $request, \app\admin\model\UserTo $userTo)
    {
        $this->request = $request;
        $this->userto = $userTo;
    }

    //添加页面展示
    public function index()
    {

        return view('userto/userto');
    }

    /**
     * @param Request $request
     * @return array|string
     * 添加页面
     */
    public function useradd(Request $request)
    {

        $info1 = $this->request->param();


        $validate = new \app\admin\validate\UserTo();

        if (!$validate->check($info1)) {
            return $validate->getError();
        }

        $arr = [];
        $file = $request->file('img');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move('../uploads');
        if ($info) {
            // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
            $arr['u_img'] = $info->getSaveName();

        }

        $arr['name'] = $request->name;
        $arr['phone'] = $request->phone;
        $arr['email'] = $request->email;
        $arr['sex'] = $request->sex;
        $arr['city'] = $request->city;

        if (!empty($request->introduce)) {
            $arr['hobby'] = implode(',', $request->hobby);
        }
        $arr['introduce'] = $request->introduce;
//        return 123;
        $a = $this->userto->save($arr);

        if ($a) {
            return redirect('userlist');
        } else {
            return '失败';
        }
    }

    /**
     * @return \think\response\View
     * @throws \think\exception\DbException
     * 展示
     */
    public function userList()
    {
        if (!empty($this->request->name)) {
            $arr['name'] = $this->request->name;
            //分页查询 带搜索  ->paginate(1,false,['query' => request()->param()])
            $data = $this->userto->where($arr)->paginate(1, false, ['query' => request()->param()]);


        } else {
            $data = $this->userto->paginate(2);
        }

//        var_dump($data);
        return view('userto/userlist', ['data' => $data]);

    }

    /**
     * @return \think\response\Redirect
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     * 删除
     */
    public function userDel()
    {
        $id = $this->request->id;

        $data = $this->userto->where('id', $id)->delete();
        if ($data) {
            return redirect('userlist');
        } else {
            return redirect('userlist');
        }
    }

    //关联查询
    public function cs()
    {
       $data=$this->userto->cs(4);



    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值