Codeigniter未定义的属性:欢迎::$session并在null上呼叫成员函式flashdata()

3qpi33ja  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(89)

我正在使用Codeigniter,但为什么我会收到这些错误(1)消息:未定义的属性:欢迎光临::$session(2)留言:对null调用成员函数flashdata()
我需要补充什么吗?谢谢
谢谢你
错误屏幕截图x1c 0d1x
Welcome.php档案:

<?php

defined('BASEPATH') or exit('No direct script access allowed');

class Welcome extends CI_Controller
{

    public function index()
    {
        $this->load->view('home');
    }

    function registerNow()
    {

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->form_validation->set_rules('fname', 'First Name', 'required|alpha');
            $this->form_validation->set_rules('mname', 'Middle Name', 'required|alpha');
            $this->form_validation->set_rules('lname', 'Last Name', 'required|alpha');
            $this->form_validation->set_rules('username', 'Username', 'required');
            $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]');
            $this->form_validation->set_rules('confirmpass', 'Confirm Password', 'required|min_length[8]|matches[password]');
            $this->form_validation->set_rules('bday', 'Birthday', 'required');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('contact', 'Contact Number', 'required|numeric');

            if ($this->form_validation->run() == TRUE) {
                $fname = $this->input->post('fname');
                $mname = $this->input->post('mname');
                $lname = $this->input->post('lname');
                $username = $this->input->post('username');
                $password = $this->input->post('password');
                $bday = $this->input->post('bday');
                $email = $this->input->post('email');
                $contact = $this->input->post('contact');

                $data = array(
                    'first_name' => $fname,
                    'middle_name' => $mname,
                    'last_name' => $lname,
                    'username' => $username,
                    'password' => sha1($password),
                    'bday' => $bday,
                    'email' => $email,
                    'contact_number' => $contact
                );

                $this->load->model('user_model');
                $this->user_model->insertuser($data);
                $this->session->flashdata('success', 'Successfully User Created');
                redirect(base_url('welcome/index'));
            }
        }
    }
}
mzaanser

mzaanser1#

调用控制器上的会话以使用会话

$this->load->library('session');

或者转到应用程序\config\autoload.php
并将会话添加到阵列

$autoload['libraries'] = array('session');

相关问题