Welcome Guest, Not a member yet? Register   Sign In
Getting value of ID from view to controller to model
#1

[eluser]Unknown[/eluser]
Hello,

I have a URL in a link on my view similar to the following:

Code:
<a href="example.com/class/gather/123">

I see how to access the ID segment in the controller:

Code:
function gather($id)
{

echo $id;

}

But I'd like to something like the following in my model:

Code:
$this->load->database();
$this->db->where('person_id', $id);
$this->db->from('people');
$query = $this->db->get('');

Access the record in the database corresponding to that ID value. Pass that back to the controller, then to the view.

I get an error about undefined variable in the model. What do I have to do to pass the value of $id to the model from controller? I didn't see any examples of this.

Thanks for the help in advance!
#2

[eluser]mattpointblank[/eluser]
Controller:

Code:
function gather($id)
{
    $this->load->model('your_model');
    $person = $this->your_model->getPerson($id)
}

Model:

Code:
function getPerson($id)
{
    return $this->db->get_where('persons', array('id' => $id))->row_array();
}

Or similar.
#3

[eluser]Unknown[/eluser]
OK! Got it to work. Many thanks.




Theme © iAndrew 2016 - Forum software by © MyBB