i have the book but its basically a rewrite of the official documentation. the author doesnt add that much really. still sometimes it helps to get another view (no pun intended) on things if the official docs arent clear.
at first its quite hard to get your head round the MVC stuff but its actually very simple: in CI, all your queries, and only queries go in the model.
here is some code from a real model i use. note that this uses activerecord to simplify queries.
class mymodel extends Model {
function mymodel() {
parent::Model(); } function
getentry($url_title) {
$this->db->where('url_title',
$url_title); return
$this->db->get('entries')->result_array();
} function getsidebar($section)
{ $this->db->where('section',
$section); $this->db->select('title,
url_title, section'); return
$this->db->get('entries')->result_array();
} }
the getentry function gets a blog post based on the url_title from the "entries" table.to use this function you do this in your controller
$blogpost =
$this->mymodel->getentry($this->uri->segment(3));
you see first $this, then the name of the model and then the name of the function. $this->uri->segment(3) is the third segment of the url in domain.com/index.php/controller/function/blog-post-title
$blogpost is now an array that holds all the data you selected in your query. you then process this array:
$data = array( 'title' =>
$blogpost['0']['title'], 'text' =>
$blogpost['0']['text'], 'img' =>
$blogpost['0']['img'], );
now $data contains your blog post data. you then pass this to the view:
$this->load->view('myview', $data);
and now in the myview.php file you can print out the $data as such
<?php print $title ?>
<?php print $text ?>
its hard to get the formatting right, id advise to copy these examples into a text editor for easier reading. anyway this is a real world example which should help you on your way :)