Welcome Guest, Not a member yet? Register   Sign In
Edit User ion auth
#1

[eluser]Unknown[/eluser]
I'm trying to create a edit_user function using the ion auth system but everytime i run this code I get this error:

An Error Was Encountered
Unable to load the requested file: Auth/edit_user.php

Any ideas would be very much appreciated Smile


//edit a user
//logged in user

function edit_user() {

if ( ! $this->ion_auth->logged_in() )
{
redirect('auth', 'refresh');
}

//validate form input
$this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('phone1', 'Phone part 1', 'required|xss_clean|min_length[3]|max_length[3]');
$this->form_validation->set_rules('phone2', 'Phone part 2', 'required|xss_clean|min_length[3]|max_length[3]');
$this->form_validation->set_rules('phone3', 'Phone part 3', 'required|xss_clean|min_length[4]|max_length[4]');
$this->form_validation->set_rules('company', 'Company', 'required|xss_clean');

if ($this->form_validation->run() == true)
{

$id = (int)$this->input->post('id');
$data = array('first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name')),
'email' => $this->input->post('email'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone1') . '-' . $this->input->post('phone2') . '-' . $this->input->post('phone3'),
);
}

if ($this->form_validation->run() == true && $this->ion_auth->update_user($id, $data) )
{ //check to see if we are editing the user
//redirect them back to the admin page
//EXECUTE THE RESET PASSWORD HERE IF CHECKED
$this->session->set_flashdata('ion_message', "User edited");
redirect('auth/index', 'refresh');
}
else
{ //display the edit 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('ion_message')));

//get posted ID if exists, else the one from uri.
//in order to get user datas from table
$id = (isset($id)) ? $id : (int)$this->uri->segment(3);

//get current user datas from table and set default form values
$user = $this->ion_auth->get_user($id);

//passing user id to view
$this->data['user_id'] = $user->id;

//get phone parts
$phoneparts=explode('-',$user->phone);

//prepare form
$this->data['first_name'] = array('name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),
);
$this->data['last_name'] = array('name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
);
$this->data['email'] = array('name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email', $user->email),
);
$this->data['company'] = array('name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
);
$this->data['phone1'] = array('name' => 'phone1',
'id' => 'phone1',
'type' => 'text',
'value' => $this->form_validation->set_value('phone1', $phoneparts[0]),
);
$this->data['phone2'] = array('name' => 'phone2',
'id' => 'phone2',
'type' => 'text',
'value' => $this->form_validation->set_value('phone2', $phoneparts[0]),
);
$this->data['phone3'] = array('name' => 'phone3',
'id' => 'phone3',
'type' => 'text',
'value' => $this->form_validation->set_value('phone3', $phoneparts[0]),
);
$this->data['id'] = array('name' => 'id',
'id' => 'id',
'type' => 'hidden',
'value' => $this->form_validation->set_value('id', $user->id),
);

$this->load->view('auth/edit_user', $this->data);

}

}
#2

[eluser]jamesduncan[/eluser]
When I run the code out of the git repo - I get the same error

I'm trying to write my own controller using the Ion Auth edit_user() function (with the generous help of Ben) so I'l try to post back if I am able to figure this out

Cheers
#3

[eluser]sanguina[/eluser]
This will definitely not load from Auth/edit_user.php

Try appending something like

/index.php/Auth/edit_user

to your base-url

#4

[eluser]jamesduncan[/eluser]
I dropped this code into my controller and its loading the view and pulling in the user profile info and pre-populating the input forms like I need - but on submit, its not actually updating the user's information in the database

I updated the code to match my view

controllers/edit.php
views/edit.php

$this->load->view('edit', $this->data);

I also added print_r($_POST); to my index function to de bug - the edit profile view is creating the array of new updated values but not entering them into the database

Any ideas?
#5

[eluser]srpurdy[/eluser]
look at the model update_user()




Theme © iAndrew 2016 - Forum software by © MyBB