我的观点有这个错误,我找不到问题出在哪里
遇到 PHP 错误
严重性:通知
消息:未定义的变量:错误
文件名:views/register_user.php
行号:5
看法:
<?php if($errors){ ?>
<div style="background:red,color:white;">
<?=$errors?>
</div>
<? } ?>
和这里的控制器
function register(){
if($_POST){
$config=array(
array(
'field'=>'username',
'label'=>'Username',
'rules'=>'trim|required|min_length[3]|is_unique[users.username]'
),
array(
'field'=>'password',
'label'=>'Password',
'rules'=>'trim|required|min_length[5]|max_length[15]'
),
array(
'field'=>'password2',
'label'=>'Password Confirmed',
'rules'=>'trim|required|min_length[5]|matches[password]'
),
array(
'field'=>'user_type',
'label'=>'User Type',
'rules'=>'required'
),
array(
'field'=>'email',
'label'=>'Email',
'rules'=>'trim|required|is_unique[users.email]|valid_email'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$data['errors']=validation_errors();
} else {
$data=array(
'username'=>$_POST['username'],
'password'=>$_POST['password'],
'user_type'=>$_POST['user_type']
);
$this->load->model('user');
$userid=$this->user->create_user($data);
$this->session->set_userdata('userID',$userid);
$this->session->set_userdata('user_type',$_POST['user_type']);
redirect(base_url().'posts');
}
}
$this->load->helper('form');
$this->load->view('header');
$this->load->view('register_user');
$this->load->view('footer');
}
我开始使用 Codeigniter,但我找不到问题...