代码点火器功能返回空白页面

时间:2016-02-01 08:49:24

标签: php codeigniter

大家好我正在学习CI,作为我的第一个应用程序,我在博客上注册用户。当我尝试访问控制器中的寄存器功能时出现问题我得到一个空白页。

以下是我的代码。

表格:

<?php echo form_open(base_url().'users/register', 'post');?>
<p>
 <?= form_label('Username', 'username');?>
  <?php $data_form = array(
                'name'=>'username',
                'size' => 50,
                'id' => 'username',
                'class' => 'form-control',
                'value' => set_value('username')
                );?>

  <?php echo form_input($data_form);?>
</p>

<p>
 <?= form_label('Password', 'password');?>
  <?php $data_form = array(
                'name'=>'password',
                'size' => 50,
                'id' => 'password',
                'class' => 'form-control'
                );?>

  <?php echo form_password($data_form);?>
</p>

<p>
 <?= form_label('Password Confirm', 'passwordconfirm');?> 
 <?php $data_form = array(
                'name'=>'passwordconfirm',
                'size' => 50,
                'id' => 'passwordconfirm',
                'class' => 'form-control'
                );?>
 <?php echo form_password($data_form);?>
</p>

<p>
  <?= form_label('Email', 'Email');?>
      <?php $data_form = array(
                'name'=>'email',
                'size' => 50,
                'id' => 'Email',
                'class' => 'form-control'
                );?>

      <?php echo form_input($data_form);?>
</p>
 </p>User Type
 <?php $options = array(
                '' => '',
                'admin' => 'admin',
                'author' => 'author',
                'user' => 'user',
                'class'=> 'form-control'
 );
 echo form_dropdown('user_type', $options,'admin');
 ?>

注册功能:

function register()
{   
    if($_POST)
    {
        $config = array(
                        array(
                                'field' => 'username',
                                'label' => 'psername',
                                'rules' => 'trim|required|min_length[10] | is_unique[users.username]'
                            ),
                        array(
                                'field' => 'password',
                                'label' => 'password',
                                'rules' => 'trim|required|min_length[5] |max_length[15]'
                            ),
                        array(
                                'field' => 'passwordconfirm',
                                'label' => 'passwordconfirm',
                                'rules' => 'trim|required|min_length[5] |matches[password]'
                        ),
                        array(
                                'field' => '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'],
                            'email' => $_POST['email']
                        );

            $this->load->model('user');
            $userid = $this->user->createuser($data);
            $this->session->set_userdata('userID', $userid);
            $this->session->set_userdata('usery_type', $_POST['user_type']);
            redirect(base_url().'posts');
        }

        $this->load->helper('form');
        $this->load->view('template/header.php');
        $this->load->view('register_user');
        $this->load->view('template/footer.php');
    }
}

0 个答案:

没有答案