[eluser]haris244808[/eluser]
i have an anchor tag like: href=\"".base_url()."file/edit_file/".$results->id."\>Click</a>
where i redirect users to a specific page using this model:
Code:
function edit_file(){
$data['page_title'] = 'Edit File';
$data['content'] = 'edit_file_view';
//from here i get the file details depending on the id
$file_id = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
$data['file_results'] = $this->files_model->select_file_by_id($file_id);
$this->load->view('includes/template', $data);
}
then in the view i user $file_results->'field form the db' to echo out the data...and it works ok
in this view i have an update button that if anychange happens it will update those fields..
here is the method where i validate fields:
Code:
function validate_file_edit(){
$file_id = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
$this->form_validation->set_error_delimiters('<div class="validation_errors">×', '</div>');
$this->form_validation->set_rules('case_nr', 'Case Nr.', 'trim|required|max_length[50]');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|max_length[50]');
$this->form_validation->set_rules('content', 'Content', 'trim|required');
$this->form_validation->set_rules('description', 'Description', 'trim|max_length[1000]');
$this->form_validation->set_rules('priority', 'Priority', 'trim|required');
if ($this->form_validation->run() == TRUE) {
$result = $this->files_model->update_file($file_id);
if ($result == TRUE) {
$this->session->set_flashdata('file_upd_succ', 'File has been updated successfully');
redirect('home');
}
else{
$this->session->set_flashdata('file_upd_fail', 'File failed to be updated');
redirect('file/edit_file');
}
}
else{
$this->form_validation->set_error_delimiters('<div class="validation_errors">×', '</div>');
$this->session->set_flashdata('validation_errors', validation_errors());
redirect('file/edit_file');
}
}
as you can see in case of validation fail i redirect to the same page again showing a message with the help of flashdata...however when redirected to that page...it shows the validation error but it gives this error for every field:
Trying to get property of non-object
as i understan it is because when it is redirected it doesnt take the file_id and selects data...
but HOW CAN I SOLVE THIS ISSUE???