• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing Data to a Model

#1
[eluser]Jesse Schutt[/eluser]
So, forums are places to ask questions, right? Hopefully you can help me out with this simple one.

I have a need to update a field on my DB. So I should have that function with in my model, correct? Here is the code for my controller

Code:
$paypal_custom_field = explode(":", $this->paypal_lib->ipn_data['custom']);

            $this->load->model('regform_model', '', TRUE);
            $this->regform_model->verify_payment($paypal_custom_field);

Here is what is in my model function called "verify_payment"

Code:
function verify_payment()
    {
    
        $this->db->where('first_name', $paypal_custom_field[ 0]);
        $this->db->where('last_name', $paypal_custom_field[ 1]);
        $this->db->where('email', $paypal_custom_field[ 2]);

        $this->db->set('payment_received', TRUE);
        $this->db->update('table_name');
    }

I just can't get this to update the "payment_received" field. If I take the code from the model and put it into my controller, it will update the field correctly. So I am assuming that it has to do with passing the array to the model.

Any ideas?

Thanks in advance!

Jesse

#2
[eluser]m4rw3r[/eluser]
You have to pass the $paypal_custom_field as a parameter to verify_payment():

Code:
// controller
$this->load->model('regform_model', '', TRUE);
$this->regform_model->verify_payment($this->paypal_lib->ipn_data['custom']);

// model
function verify_payment($field)
    {
        $paypal = explode(":", $field);
        $this->db->where('first_name', $paypal[0]);
        $this->db->where('last_name', $paypal[1]);
        $this->db->where('email', $paypal[2]);

        $this->db->set('payment_received', TRUE);
        $this->db->update('table_name');
    }

#3
[eluser]Jesse Schutt[/eluser]
Haven't I already done that by passing the $paypal_custom_field array?

#4
[eluser]m4rw3r[/eluser]
No:
Code:
function verify_payment()
And you can also check if it really exists a matching row (see the profiler for the query and then test run it in phpmyadmin (the where part, to see if it matches anything)).

#5
[eluser]Jesse Schutt[/eluser]
So it needs to be in both the () inside of the controller as well as in the model?

#6
[eluser]Jesse Schutt[/eluser]
Also, is it better to run the explode in the model, rather than the controller?

#7
[eluser]Jesse Schutt[/eluser]
Wow! It worked!

So I pass whatever I want in the controller and than I can use it by whatever variable I assign it in the model?

Code:
//controller

$this->model->function(Whatever I want here)

//model
function($variable) {
echo $variable; //Whatever I want here
}

#8
[eluser]m4rw3r[/eluser]
yeah

#9
[eluser]Jesse Schutt[/eluser]
Thanks for your time!

#10
[eluser]m4rw3r[/eluser]
You're welcome.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.