我正在使用Codeigniter
中的Grocery Crud和Ion Auth库。尝试创建用户时不会调用callback_insert
。 callback_insert和callback_update有效
Chrome控制台不显示任何消息。当我将print_r ($post_array)
放在_create_user
函数中时,出现以下消息:
未捕获到的SyntaxError:JSON中位置0处的意外令牌A。
我已经尝试过重命名该功能,但是它不起作用。
function __construct() {
parent::__construct();
}
function _render_output($output = null) {
$data['title'] = 'Gerir utilizadores';
$output->data = $data;
$this->load->view('includes/header_crud', (array) $output);
$this->load->view('crud_view', (array) $output);
$this->load->view('includes/footer_crud', (array) $output);
}
function gerir() {
try {
$crud = new grocery_CRUD();
$crud->set_table('users');
$crud->set_subject('Utilizador');
//FORM LAYOUT
$crud->unset_export();
$crud->unset_print();
$crud->columns('username', 'email', 'active', 'last_login');
$crud->display_as('username', 'Nome')
->display_as('active', 'Estado')
->display_as('first_name', 'Primeiro nome')
->display_as('last_name', 'Último nome')
->display_as('last_login', 'Último login')
->display_as('password_confirm', 'Confirmar password');
$crud->add_fields('first_name', 'last_name', 'email', 'password', 'password_confirm');
$crud->edit_fields('first_name', 'last_name', 'email');
//VALIDATION
$crud->required_fields('first_name', 'last_name', 'email', 'password', 'password_confirm');
$crud->set_rules('email', 'E-mail', 'required|valid_email');
$crud->set_rules('password', 'Password', 'required|matches[password_confirm]');
//FIELD TYPES
$crud->change_field_type('last_login', 'readonly');
$crud->change_field_type('last_login', 'readonly');
$crud->change_field_type('password', 'password');
$crud->change_field_type('password_confirm', 'password');
//CALLBACKS
$crud->callback_insert(array($this, '_create_user'));
$crud->callback_update(array($this, 'edit_user'));
$crud->callback_delete(array($this, 'delete_user'));
//OUTPUT
$output = $crud->render();
$this->_render_output($output);
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
}
function _create_user($post_array) {
try {
$username = $post_array['first_name'] . ' ' . $post_array['last_name'];
$password = $post_array['password'];
$email = $post_array['email'];
$data = array(
'first_name' => $post_array['first_name'],
'last_name' => $post_array['last_name'],
);
$this->ion_auth_model->register($username, $password, $email, $data);
return $this->db->insert_id();
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
}
function delete_user($primary_key) {
if ($this->ion_auth_model->delete_user($primary_key)) {
return true;
} else {
return false;
}
}
function edit_user($post_array, $primary_key = null) {
$username = $post_array['first_name'] . ' ' . $post_array['last_name'];
$email = $post_array['email'];
$data = array(
'username' => $username,
'email' => $email,
'first_name' => $post_array['first_name'],
'last_name' => $post_array['last_name'],
);
$this->ion_auth_model->update($primary_key, $data);
return true;
}
我想使用Ion Auth模型创建用户