Codeigniter: Library function--I'm stuck
Posted
by Kevin Brown
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Brown
Published on 2010-05-11T20:06:34Z
Indexed on
2010/05/11
20:14 UTC
Read the original article
Hit count: 256
I have a library function that sets up my forms, and submits data. They're long, and they work, so I'll spare you reading my code. :)
I simply need a way for my functions to determine how to handle the data.
Until now, the function did one thing: Submit a report for the current user. NOW, the client has requested that an administrator also be able to complete a form--this means that the form would be filled out, and it would CREATE a user at the same time, whereas the current function EDITS and is accessed by an EXISTING user.
Do I need a separate function to do essentially the same thing?
How do I make one function perform two tasks? One to update a user, and if there is no user, create one.
Current controller:
function survey()
{
$id = $this->session->userdata('id');
$data['member'] = $this->home_model->getUser($id);
//Convert the db Object to a row array
$data['manager'] = $data['member']->row();
$manager_id = $data['manager']->manager_id;
$data['manager'] = $this->home_model->getUser($manager_id);
$data['manager'] = $data['manager']->row();
$data['header'] = "Home";
$this->survey_form_processing->survey_form($this->_container,$data, $method);
}
Current Library:
function survey_form($container)
{
//Lots of validation stuff
$this->CI->validation->set_rules($rules);
if ( $this->CI->validation->run() === FALSE )
{
// Output any errors
$this->CI->validation->output_errors();
}
else
{
// Submit form
$this->_submit();
}
$this->CI->load->view($container,$data);
The submit function is huge too. Basically says, "Update table with data where user_id=current user"
I hope this wasn't too confusing. I'll create two functions if need be, but I'd like to keep redundancy down! }
© Stack Overflow or respective owner