我正在尝试使用代码点火器2.1.0设计用户注册表单。我在控制器的regitration.php中使用了以下代码来添加用户。
class Registration extends CI_Controller
{
function __construct() {
parent::__construct();
}
function index()
{
$data['main_content'] = 'registration';
// Checks to see if form validation rules were met an executed properly. If not, will return with registration form.
if ($this->form_validation->run('registration') === FALSE)
{
$data ['title'] = 'Registration';
$this->load->view('include/template', $data);
}
// If validation passes, information will be passed along to the MODEL to be processed and the account will be created.
else
{
$this->load->model('registration_model');
$this->registration_model->addUser();
$this->session->set_flashdata('success', 'Your account has been successfully created');
redirect(uri_string());
}
}
}
但它显示了Call to a member function run() on a non-object
的错误。我该如何纠正?
答案 0 :(得分:3)
请包含
// load 'form' helper
$this->load->helper('form');
// load 'validation' class
$this->load->library('form_validation');
立即尝试
function __construct() {
// load controller parent
parent::__construct();
// load 'url' helper
$this->load->helper('url');
// load 'form' helper
$this->load->helper('form');
// load 'session'
$this->load->library('session');
// load 'validation' class
$this->load->library('form_validation');
}
好像$ session类没有正确初始化。
对于此"In order to use the Session class you are required to set an encryption key in your config file."
。
将此添加到您的config.php
$config['encryption_key'] = 'your_encryption_key_here';