[eluser]swgj19[/eluser]
Yes to all:
1. I configured the autoload.php:
Code:
$autoload['libraries'] = array('database');
and
Code:
$autoload['helper'] = array('url');
2. I configured the config.php:
Code:
$config['base_url'] = 'http://localhost/ci/index.php';
and
Code:
$config['index_page'] = 'index.php';
3. I configured routes.php:
Code:
$route['default_controller'] = "site";
Code:
$route['404_override'] = '';
database.php
Code:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'ci_series';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Controller(site.php):
Code:
<?php
class Site extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->model('site_model'); //This is where model is loaded, but nothing done with the model yet.
$data['records'] = $this->site_model->getAll();
$this->load->view('home', $data);
}
}
?>
Model(site_model.php)
Code:
<?php
class Site_model extends CI_Model {
function getAll() { //can name method whatever
$q = $this->db->get('test'); //grab table name:test from database name: ci_series
if($q->num_rows() > 0) { //If # of rows return are > than 0, then do whats next.
foreach ($q->result() as $row)
{
$data[] = $row; //by setting $data as an array, we have a new instance in the data array.
}
return $data;
}
}
}
?>
Views(home.php)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="container">
<p>My view has been loaded</p>
<?php foreach($records as $row) : ?>
<h1><?php echo $row->username; ?></h1>
<?php endforeach; ?>
</div>
</body>
</html>
I have done everything I know to do and researched google in and out and the codeignitor forums.