0

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

Edited by wycliffe.ottawa

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by wycliffe.ottawa
0

@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

Edited by LastMitch: grammer

1

$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).

0

$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! =)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.