Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Passing Array Data to Model
#1

[eluser]Unknown[/eluser]
Sorry guys,

This might be a silly question... still new to MVC framework and CI. Hope you understand.

I have a controller called create_account and a model called membership_model. In the controller I have a function that loaded the model and adds data to the database from the view.

My problem: I have an array of data that I need to pass to the model so it can be stuffed into the database. I have no problem with adding the post data from the form. How do I add the arrayed data from the controller and pass it to the model for db insertion? Thanks for any help on this one.

Here is the controller snippet: The $httpParsedResponseAr is the arrayed data that needs passed to the database and it does have data.

Code:
<?php
        $httpParsedResponseAr = $this->paypal->PPHttpPost($methodToCall, $nvpStr);
        $ack = strtoupper($httpParsedResponseAr["ACK"]);
                      
                if($ack!="SUCCESS") {

                    $data['responce'] = $httpParsedResponseAr;
                    
                    // Add member to database using -> application/model/membership_model.php create_member() function
                    $this->load->model('membership_model');
                    $this->membership_model->create_member();
                    
                    $data['main_content'] = 'site/step3_fail_view';
                    $this->load->view('site_template/template', $data);
}


?>

And the Model that has the arrayed var $responce['PROFILEID'].

Code:
<?php
    function create_member() {
                
        $new_member_insert_data = array(
            'pp_profileID'     => $responce['PROFILEID'],
            'first_name'     => $this->input->post('first_name'),
            'last_name'     => $this->input->post('last_name'),
            'email_address' => $this->input->post('email'),
            'password'         => $this->encode5t($this->input->post('password'))
        );
        
        $insert = $this->db->insert('membership', $new_member_insert_data);
        return $insert;
    }
?>
#2

[eluser]Tominator[/eluser]
So, you can change your line:
Code:
function create_member() {
to:
Code:
function create_member($input) {
in your model.

Than you can call it easily:
Code:
$this->membership_model->create_member($some_data);
#3

[eluser]Unknown[/eluser]
Thanks, so it works just like any other function you would pass data to... haha.

Sorry Wink BTW, how would I mark this post as [SOLVED]?
#4

[eluser]InsiteFX[/eluser]
Edit your orginal post and add [SOLVED] to it...

Enjoy
InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB