am creating a simple blog application and i have a model in ci called entries model and one particular function that gets a blog entry by id from an entries table table in a database this here is the code

<?php
class Entries_model extends CI_Model{
function __construct(){
 parent::__Construct();
 }
function get_comment($id){
$query = $this->db->where('id',$id);
$query = $this->db->get('entries');
}

i am coding according to a tutorial i did so i know this is a damn question but where does the $id parameter come from? does codigniter automatically assume that this parameter comes from the third section of the uri
?
thanks

Member Avatar for LastMitch

@wycliffe.ottawa

The little code you provided is very hard to figure out. In the future try to post a little more than that.

i am coding according to a tutorial i did so i know this is a damn question but where does the $id parameter come from?

Regarding about how the $id parameter came from read this:

http://codeigniter.com/user_guide/general/creating_libraries.html

This is wrong:

$query = $this->db->where('id',$id);

it should be this:

$query = $this->db->where('id');

does codigniter automatically assume that this parameter comes from the third section of the uri

Regarding about uri read this:

http://codeigniter.com/user_guide/libraries/uri.html

$query = $this->db->where('id',$id);

That's actually correct, it's part of the Active Record driver for the DB. The $id variable is loaded from the URI websitename.com/folder(optional)/class/function/variables

So if you were to goto for example websitename.com/entries_model/get_comment/12/ CI would basically interpurate that as load the Entrie_model class, run the get_comment function and pass 12 to it as a variable (which is assigned to the $id as per the function constructor).

Member Avatar for LastMitch

$query = $this->db->where('id',$id);

That's actually correct, it's part of the Active Record driver for the DB. The $id variable is loaded from the URI websitename.com/folder(optional)/class/function/variables

This has to be a Oops moment! =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.