首页 >社区问答列表 >这行代码 $user= UserModel::create($request->param()); 执行的时候没反应不知道哪里错了

这行代码 $user= UserModel::create($request->param()); 执行的时候没反应不知道哪里错了

//添加操作
public function addUser(Request $request)
{
   $data = $request -> param();
   $status = 1;
   $message = '添加成功';

   $rule = [
       'name|用户名' => "require|min:3|max:10",
       'password|密码' => "require|min:3|max:10",
       'email|邮箱' => 'require|email'
   ];

   $result = $this -> validate($data, $rule);
   //return ['status'=>$status, 'message'=> $result ];

   if ($result === true) {
     //  return ['status'=>$status, 'message'=>$request->param()];
     $user= UserModel::create($request->param());
       

       if ($user === null) {
           $status = 0;
           $message = '添加失败~~';
       }
   }


  return ['status'=>$status, 'message'=>$message];
}

  • You bad bad
  • You bad bad     2018-07-13 16:34:52 3楼

    你的  return ['status'=>$status, 'message'=>$message];   。不是应该用assign()吗。还有目测是数据类型错误。把你的数据变量比如$data加个[0]。。。$data[0]输出看看

    +0 添加回复

  • 回复

    O(∩_∩)O谢谢 问题出在 $data[0], 输出是['/index/user/adduser_html':‘ ’] 所以错误,表单里面没有这个的,为啥 朱哥 视频里面没出问题。奇怪

    紫轩 ADG   作者 · 2018-07-14 07:07:49
    回复
  • 紫轩 ADG
  • 紫轩 ADG     2018-07-11 17:43:15 2楼

    [0] InvalidArgumentException in Response.php line 316


    1531302174739456.jpg

    variable type error: array

       {       

     if (null == $this->content) { 

               $content = $this->output($this->data);   

             if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([    

                $content,                '__toString',          

      ])            ) {            

        throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));           

     }            $this->content = (string) $content;        }     

       return $this->content;    }    /**     * 获取状态码


    Call Stack

    in Response.php line 316

    at Response->getContent() in Response.php line 94

    at Response->send() in start.php line 19

    at require('D:\php\tp5\thinkphp\...') in index.php line 17

    Environment Variables

    GET Data

    /index/user/adduser_html

    POST Data

    empty

    Files

    empty

    Cookies

    thinkphp_show_page_trace

    0|0

    PHPSESSID

    b1e4csbk4p7etj8p50l4m9r0r6

    Session

    think

    { "user_id": 1, "user_info": { "id": 1, "name": "admin", "password": "e10adc3949ba59abbe56e057f20f883e", "email": "admin123@php.cn", "role": 1, "status": 1, "create_time": 1501493848, "update_time": 1531298974, "delete_time": null, "login_time": 1531298973, "login_count": 23, "is_delete": 1 } }

    Server/Request Data

    PATH

    C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\

    SYSTEMROOT

    C:\Windows

    COMSPEC

    C:\Windows\system32\cmd.exe

    PATHEXT

    .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

    WINDIR

    C:\Windows

    PHP_FCGI_MAX_REQUESTS

    1000

    PHPRC

    C:/myphp_www/PHPTutorial/php/php-5.6.27-nts/

    _FCGI_SHUTDOWN_EVENT_

    1796

    SCRIPT_NAME

    /index.php

    REQUEST_URI

    /index/user/adduser.html

    QUERY_STRING

    /index/user/adduser.html

    REQUEST_METHOD

    GET

    SERVER_PROTOCOL

    HTTP/1.1

    GATEWAY_INTERFACE

    CGI/1.1

    REDIRECT_QUERY_STRING

    /index/user/adduser.html

    REDIRECT_URL

    /index/user/adduser.html

    REMOTE_PORT

    51873

    SCRIPT_FILENAME

    D:/php/tp5/public/index.php

    SERVER_ADMIN

    admin@php.cn

    CONTEXT_DOCUMENT_ROOT

    D:/php/tp5/public

    CONTEXT_PREFIX

    REQUEST_SCHEME

    http

    DOCUMENT_ROOT

    D:/php/tp5/public

    REMOTE_ADDR

    127.0.0.1

    SERVER_PORT

    80

    SERVER_ADDR

    127.0.0.1

    SERVER_NAME

    www.tp5.cn

    SERVER_SOFTWARE

    Apache/2.4.23 (Win32) OpenSSL/1.0.2j mod_fcgid/2.3.9

    SERVER_SIGNATURE

    SystemRoot

    C:\Windows

    HTTP_COOKIE

    thinkphp_show_page_trace=0|0; PHPSESSID=b1e4csbk4p7etj8p50l4m9r0r6; thinkphp_show_page_trace=0|0

    HTTP_ACCEPT_LANGUAGE

    zh-CN,zh;q=0.9

    HTTP_ACCEPT_ENCODING

    gzip, deflate

    HTTP_ACCEPT

    text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

    HTTP_USER_AGENT

    Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

    HTTP_UPGRADE_INSECURE_REQUESTS

    1

    HTTP_CONNECTION

    close

    HTTP_HOST

    www.tp5.cn

    REDIRECT_STATUS

    200

    FCGI_ROLE

    RESPONDER

    PHP_SELF

    /index.php

    REQUEST_TIME_FLOAT

    1531301786.1009

    REQUEST_TIME

    1531301786

    PATH_INFO

    /index/user/adduser.html

    Environment Variables

    empty

    ThinkPHP Constants

    APP_PATH

    D:\php\tp5\public/../application/

    THINK_VERSION

    5.0.20

    THINK_START_TIME

    1531301786.1089

    THINK_START_MEM

    144840

    EXT

    .php

    DS

    \

    THINK_PATH

    D:\php\tp5\thinkphp\

    LIB_PATH

    D:\php\tp5\thinkphp\library\

    CORE_PATH

    D:\php\tp5\thinkphp\library\think\

    TRAIT_PATH

    D:\php\tp5\thinkphp\library\traits\

    ROOT_PATH

    D:\php\tp5\

    EXTEND_PATH

    D:\php\tp5\extend\

    VENDOR_PATH

    D:\php\tp5\vendor\

    RUNTIME_PATH

    D:\php\tp5\runtime\

    LOG_PATH

    D:\php\tp5\runtime\log\

    CACHE_PATH

    D:\php\tp5\runtime\cache\

    TEMP_PATH

    D:\php\tp5\runtime\temp\

    CONF_PATH

    D:\php\tp5\public/../application/

    CONF_EXT

    .php

    ENV_PREFIX

    PHP_

    IS_CLI

    false

    IS_WIN

    true

    USER_ID

    1

    ThinkPHP V5.0.20 { 十年磨一剑-为API开发设计的高性能框架 }

    0.103005s


    +0 添加回复

  • 回复