It seems there is no ready solution. Here is the closest thing i got to a working code yet its still not working... validation is not passed and users are not saved or created.
⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠
Posted 25 February 2013 - 07:22 AM
It seems there is no ready solution. Here is the closest thing i got to a working code yet its still not working... validation is not passed and users are not saved or created.
Posted 02 August 2013 - 20:10 PM
how to include the select user group (or replicate) the function just like in the /view/auth/edit_user?
---edit
apparently set_relation_n_n just works fine for this function :D
Posted 13 August 2013 - 15:20 PM
function list_users($operation = null) { $this -> load -> helper('url'); $this -> class_name = strtolower(__CLASS__); try { $crud = new grocery_CRUD(); $crud -> set_theme('flexigrid'); $crud -> set_table('users'); $crud -> set_relation_n_n('groupname', 'users_groups', 'groups', 'user_id', 'group_id', 'name'); if ($operation == 'edit') { $crud -> fields('username', 'first_name', 'last_name', 'password', 'email', 'identifier', 'groupname', 'created_on', 'last_login', 'company', 'active'); $crud -> change_field_type('created_on', 'readonly'); } else { $crud -> fields('username', 'first_name', 'last_name', 'password', 'email', 'identifier', 'groupname', 'created_on', 'last_login', 'company', 'active'); $crud -> change_field_type('created_on', 'hidden'); } $crud -> required_fields('username', 'password', 'email', 'groupname', 'active', 'users_group', 'first_name', 'last_name', 'identifier'); $crud ->display_as('username','Username') ->display_as('first_name','Nume') ->display_as('last_name','Prenume') ->display_as('password','Parola') ->display_as('email','Email') ->display_as('identifier','Identificator(Necesita sa fie unic)') ->display_as('groupname','Nume grup') ->display_as('created_on','Creat la data') ->display_as('last_login','Ultimul login') ->display_as('company','Companie') ->display_as('active','Activ') ; $crud -> set_rules('password', 'Parola', 'min_length[' . $this -> config -> item('min_password_length', 'ion_auth') . ']|max_length[' . $this -> config -> item('max_password_length', 'ion_auth') . ']'); $crud -> set_rules('email', 'Email','required|valid_email'); $crud -> columns('username', 'first_name', 'last_name', 'email', 'identifier', 'groupname', 'created_on', 'last_login', 'social_network', 'active'); $crud -> callback_column('created_on', array($this, 'datetime')); $crud -> callback_column('last_login', array($this, 'datetime')); $crud -> change_field_type('last_login', 'readonly'); // $crud -> change_field_type('ip_address', 'readonly'); $crud -> change_field_type('password', 'password'); $crud -> change_field_type('ip_address', 'readonly'); $crud -> callback_before_insert(array($this, 'insert_encrypt_password_callback')); $crud -> callback_before_update(array($this, 'edit_encrypt_password_callback')); $crud -> callback_edit_field('password', array($this, 'decrypt_password_callback')); // $crud->callback_edit_field('ip_address', array($this, 'ip_address')); $crud -> callback_edit_field('created_on', array($this, 'datetime')); $crud -> callback_edit_field('last_login', array($this, 'datetime')); $data['output'] = $crud -> render(); $this -> gc_title = 'Administrare Useri'; $this -> layout -> view($this -> admin_dir . 'gc_data/v_listdata', $data); } catch(Exception $e) { show_error($e -> getMessage() . ' --- ' . $e -> getTraceAsString()); } } function ip_address($value, $row) { return @inet_ntop($value); } function datetime($value, $row) { return @date('d M Y H:i:s', $value); } function insert_encrypt_password_callback($post_array, $primary_key = null) { $this -> load -> model('ion_auth_model'); $post_array['password'] = $this -> ion_auth_model -> hash_password($post_array['password']); $post_array['created_on'] = now(); return $post_array; } function edit_encrypt_password_callback($post_array, $primary_key = null) { $this -> load -> model('ion_auth_model'); if ($post_array['password'] == 'defaultvalue') { unset($post_array['password']); } else { $post_array['password'] = $this -> ion_auth_model -> hash_password($post_array['password']); } return $post_array; } function decrypt_password_callback($value) { return "<input type='password' name='password' value='defaultvalue' />"; }
I`v made it work more simplier,
Note that i have 2 more fields in the above example in user table that you can remove (identifier,social_network).
An also you need to watch $this -> layout -> view($this -> admin_dir . 'gc_data/v_listdata', $data); , i`m using an layout library so you just need to pass the data to view.