Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Accessing form data in model
#1

[eluser]Jacob Graf[/eluser]
Why doesn't this work? Ohh, and db_m model is autoloaded. Form data is submitted to this controller...

Code:
function save() {
    $this->db_m->save($_POST);
}

and I can't get to the form data in the model...

Code:
function save($input) {
    $data = array(
        'event_name' => $event_name
    );
    $this->db->insert('events', $data);
}

Sorry. I haven't coded in CI for a while and I bet this is something simple! Erghh!
#2

[eluser]mi6crazyheart[/eluser]
Code:
function save($input) {
    $data = array(
        'event_name' => $event_name
    );
    $this->db->insert('events', $data);
}

from where that "$event_name" variable & it's value is coming ... ?
#3

[eluser]Jacob Graf[/eluser]
It was my understanding that when you pass an array to a model (the $_POST array), it will explode itself into single variables. One of the fields posted to the controller is named event_name.
#4

[eluser]Jacob Graf[/eluser]
Ok. I got it figured out! First off, when you pass data to a model, it is not exploded. Only when you pass data to a view. Also ... drum-roll please ...

I forgot to load the database library :-(

Thanks for your help!




Theme © iAndrew 2016 - Forum software by © MyBB