Welcome Guest, Not a member yet? Register   Sign In
Customer model design question

I have a Customer model in a program I am building.

A customer has the following fields in the database table.

first_name, last_name, phone_number, email, street_address, state, zip, comments (and possible more)

In my Model I have a function to save (insert or update) a customer.

function save_customer($customer_id, $first_name, $last_name, $phone_number, $email, $street_address, $state, $zip, $comments)

As you can tell the function has a LOT of parameters. Is this considered a bad practice? Should I just have one array that contains field=>value references? What do you do?

For me I pass the post array to the model here is an example.

1. Controler which passes the form data to the model.
// $data will hold your post array
$data = $this->input->post('input');
if ($this->validation->run() == FALSE):
    // Post your error report
    if ( $this->News_model->insert_news( $this->input->post('input'))):
        // success do whatever
        // Post error

2. Then in the model I check against any missing data and enter data. Here is a very simple example.
function insert_news( $data )
    $checks = array('title', 'body', 'etc');
    foreach($checks as $check):
        if( $check == ''):
            return FALSE;
    // Add Date
    $data['date'] = time();
        return false;                        
      return true;

Hope this helps.

Theme © iAndrew 2016 - Forum software by © MyBB