首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“$validate”已声明,但未声明为used.intelephense

“$validate”已声明,但未声明为used.intelephense
EN

Stack Overflow用户
提问于 2021-10-28 23:22:33
回答 1查看 42关注 0票数 0

这是我用来创建登录和注册页面的程序

在验证部分中,我没有找到语法函数,也没有找到更改,您能帮我吗?

使用:intelephense

代码语言:javascript
复制
 $validate = $this->validation->run($data, 'register');

代码:

代码语言:javascript
复制
public function  __construct()
{
    helper(['form', 'url']);
    $this->validation = \Config\Services::validation();
    $this->session = session();
}


            $data = $this->request->getPost();
            $validate = $this->validtion->run($data, 'register');
            $errors = $this->validation->getErrors();

            // Data2
            if (!$errors) {
                $this->model = new UserModel();

                $user = new \App\Entities\Users();

                $user->username        = $this->request->getPost('username');
                $user->name            = $this->request->getPost('name');
                $user->name_instansi   = $this->request->getPost('name_instansi');
                $user->alamat_instansi = $this->request->getPost('alamat_instansi');
                $user->email           = $this->request->getPost('email');
                $user->password        = $this->request->getPost('password');
                $user->repeatPassword  = $this->request->getPost('repeatPassword');


                $user->created_by = 0;

                $user->created_date = date("Y-m-d H:i:s");

                $user = $this->userModel->save($user);

                return view('login');
            }
            $this->session->setFlashdata('errors', $errors);
        }

        return view('/Geolab/auth/register');
    }
EN

回答 1

Stack Overflow用户

发布于 2021-10-29 02:18:38

我不太明白你的问题。问题标题中错误的来源在错误消息中。您可以使用以下代码行创建$validate变量:

代码语言:javascript
复制
$validate = $this->validation->run($data, 'register');

但是,您不能在其他任何地方使用$validate变量。你确定没有你想用的地方吗?也许下一行应该是$errors = $validate->getErrors()?我不能肯定,因为我不知道你的validation类是什么。但问题中的错误实际上是因为您没有在其他地方使用$validate;如果这是故意的,请不要创建变量并将行更改为:

代码语言:javascript
复制
$this->validation->run($data, 'register'); // don't save result to a variable you're not using
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69762000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档