I want to create keys based on the information provided by the user. For example, if a user inserts their name, phone, country and some other information then my code should concatenate some fields and store a unique key into the same user table where I have field key. Example:
JACK-691-INDIA-10-001
So here, Jack would be the name inserted by user, 691 would be country code India is name of country, 10 is no of users and 001 is his database id.
In model I have a function get_new()
where I initialize all the variables in array and I want to concatenate some variables and form a string(key) to be saved in key field.
The Model:
public function get_new(){
$user = new stdClass();
// $user->id = '';
$user->sip_username='';
$user->sip_password='';
$user->key='';
$user->allocation_block='';
$user->name='';
$user->email = '';
$user->password = '';
$user->phone='';
$user->user_num='';
$user->address = '';
$user->status = '';
$user->country='';
$user->created = '';
$user->modified = '';
$user->balance = '';
return $user;
$this->session->set_userdata($data);
}
The Controller Edit method :
public function edit ($id = NULL)
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->reseller_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else {
$this->data['user'] = $this->reseller_m->get_new();
}
// Set up the form
$rules = $this->reseller_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->reseller_m->array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','created','modified','status'));
$data['password'] = $this->reseller_m->hash($data['password']);
$key=$this->reseller_m->save($data, $id);
$this->db->insert_id();
/* $key=$this->reseller_m->save($data, $key); $data['key'] =$this->reseller_m->insert_item($data['name'].$data['phone']);
*/
for($i=1; $i<=$data['user_num'];$i++)
{
$userdata=array('key'=>$key);
// here users is taken name of user table with retailer_id is field
$this->user_m->save($userdata,$id);
}
redirect('admin/reseller');
}
// Load the view
$this->data['subview'] = 'admin/reseller/edit';
$this->load->view('admin/_layout_main', $this->data);
}