[eluser]notebook[/eluser]
Hi
i am trying to use code from the book "Codeigniter 1.7" by Jose Argudo; David Upton.Please help.
It is giving me this error :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Sites_model::$db
Filename: models/sites_model.php
Line Number: 11
Fatal error: Call to a member function get() on a non-object in C:\wamp\www\codeig\system\application\models\sites_model.php on line 11
Controller (site.php)
Code:
<?php
class Sites extends Controller
{
function Sites()
{
parent:: Controller( ) ;
}
function index( )
{
//First we load the library and the model
$this->load->library('table') ;
$this->load->model('sites_model') ;
//Then we call our model's get_sites function
$sites = $this->sites_model->get_sites( );
//If it returns some results we continue
if ($sites->num_rows( ) >0)
{
//Prepare the array that will contain the data
$table = array( );
//Prepare the table headers , one column for each table field
$table[ ] = array( 'id' , 'name' , 'url' , 'un' , 'pw',
'client1' , 'client2' , 'admin1',
'admin2' , 'domainid' , 'hostid',
'webroot' , 'files' , 'filesdate',
'lastupdate' , 'submit');
//Then we loop through our query results
foreach($sites->result( ) as $row)
{
//For each one of the results we create an array of values , one
//for each field , that will be under our table headers
$table[ ] = array ($row->id ,$row->name ,$row->url,
$row->un ,$row->pw ,$row->client1,$row->client2 ,$row->admin1 ,$row->admin2,$row->domainid ,$row->hostid,
$row->webroot,$row->files, $row->filesdate, $row->lastupdate ,$row->submit);
}
//Next step is to place our created array into a new array
//variable , one that we are sending to the view.
$data ['sites'] = $table;
}
//Also we put into that array another variable , "heading" that we
//will use to echo the heading title
$data['heading'] = "Sites admin";
//Now we are prepared to call the view passing all the necessary variables
//inside the $data array
$this->load->view('sites/index',$data);
}
}
Model (sites_model.php)
Code:
<?php
class Sites_model extends Model
{
function sites_model()
{
parent::Model();
}
function get_sites()
{
$query = $this->db->get('sites');
return $query;
}
}
?>
View (/views/sites/index.php)
Code:
<?php
//First we echo the $heading variable
echo " <h1>".$heading."</h1>" ;
//And if the $site variable is not empty we echo it' s content by
//using the generate method of the table class / library
if( !empty($sites) ) echo $this->table->generate($sites) ;
?>