我是Ion Auth codeigniter库的新手。现在我正在制作一个自定义引导程序表单来添加使用模态的用户,但我总是得到错误。任何帮助将非常感激。模态位于userList.php视图中,显示所有注册用户。
Controller:Users.php
function create_user()
{
$this->data['title'] = "Create User";
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}
$tables = $this->config->item('tables','ion_auth');
$identity_column = $this->config->item('identity','ion_auth');
$this->data['identity_column'] = $identity_column;
// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('create_user_validation_fname_label'), 'required');
$this->form_validation->set_rules('last_name', $this->lang->line('create_user_validation_lname_label'), 'required');
if($identity_column!=='email')
{
$this->form_validation->set_rules('identity',$this->lang->line('create_user_validation_identity_label'),'required|is_unique['.$tables['users'].'.'.$identity_column.']');
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email');
}
else
{
$this->form_validation->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email|is_unique[' . $tables['users'] . '.email]');
}
$this->form_validation->set_rules('phone', $this->lang->line('create_user_validation_phone_label'), 'trim');
$this->form_validation->set_rules('company', $this->lang->line('create_user_validation_company_label'), 'trim');
$this->form_validation->set_rules('password', $this->lang->line('create_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', $this->lang->line('create_user_validation_password_confirm_label'), 'required');
if ($this->form_validation->run() == true)
{
$email = strtolower($this->input->post('email'));
$identity = ($identity_column==='email') ? $email : $this->input->post('identity');
$password = $this->input->post('password');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
);
var_dump($first_name);
}
if ($this->form_validation->run() == true && $this->ion_auth->register($identity, $password, $email, $additional_data))
{
// check to see if we are creating the user
// redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth", 'refresh');
}
else
{
// display the create user form
// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name'),
);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name'),
);
$this->data['identity'] = array(
'name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company'),
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone'),
);
$this->data['password'] = array(
'name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
);
$this->data['password_confirm'] = array(
'name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
);
$this->_render_page('userList', $this->data);
}
}
查看:userList.php
<div class="modal fade" id="add-user" role="dialog">
<div class="modal-dialog modal-default">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 id="modal-user-profile" class="modal-title">Add User</h4>
</div>
<div class="modal-body">
<?php echo form_open('users/create_user', ['class' => 'form-horizontal', 'role' => 'form']); ?>
<div class="form-group">
<label for="first_name" class="col-sm-2 control-label">First Name</label>
<div class="col-sm-10">
<?php echo form_input($first_name);?>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<?php echo form_password(['name' => 'password', 'id' => 'password', 'class' => 'form-control', 'placeholder' => 'Password']); ?>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Confirm Password</label>
<div class="col-sm-10">
<?php echo form_password(['name' => 'password_confirm', 'id' => 'password_confirm', 'class' => 'form-control', 'value' => set_value('password_confirm'), 'placeholder' => 'Confirm Password']); ?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<?php echo form_input(['name' => 'email', 'id' => 'email', 'class' => 'form-control', 'value' => set_value('email'), 'placeholder' => 'Email']); ?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Contact No</label>
<div class="col-sm-10">
<?php echo form_input(['name' => 'contact', 'id' => 'contact', 'class' => 'form-control', 'value' => set_value('contact'), 'placeholder' => 'Contact']); ?>
</div>
</div>
<div class="form-group">
<label for="status" class="col-sm-2 control-label">Group</label>
<div class="col-sm-10">
<select class="form-control" id="group">
<option>--</option>
<option>Admin</option>
<option>Client</option>
<option>BIR</option>
</select>
</div>
</div>
<div class="form-group">
<label for="status" class="col-sm-2 control-label">Status</label>
<div class="col-sm-10">
<select class="form-control" id="status">
<option>--</option>
<option>Active</option>
<option>Inactive</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default create-user">Create</button>
<button type="button" class="btn btn-danger create">Cancel</button>
</div>
</div>
<?php echo form_close(); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
你得到了什么错误? 在控制器中,使用此选项验证结果
查询后; echo $ this-&gt; db-&gt; last_query();
的var_dump($ _ POST);出口;
首先检查所有发布的数据和查询,然后告诉您的错误