[eluser]ehicks727[/eluser]
Here's an MVC pattern that I use a lot. I hope it helps out your understanding of MVC.
Controller (controllers/test.php)
Code:
<?php
class Test extends Controller
{
function __construct () {
parent::Controller();
$this->data = array(
'titletag' => 'This is the title tag',
'metadescription' => 'This is your metadescription',
'metakeywords' => 'These are your metakeywords',
'content_view' => '',
'content_data' => ''
);
}
function index () {
$this->load->model('test_model');
if ($this->test_model->getSomeData()) {
$this->data['content_data'] = $this->test_model->getSomeData();
}
$this->data['content_view'] = 'homepage';
$this->load->view('template', $this->data);
}
}
Model (models/test_model.php)
Code:
class Test_Model extends Model {
function Test_Model() {
parent::Model();
$db = $this->load->database();
}
function getSomeData() {
$query = $this->db->query("SELECT * FROM db.tbl;" );
return $query->num_rows() ? $query->result() : false;
}
|
Template View (views/template.php) (this is the HTML template that 'skins' your site)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<title><?=$titletag;?></title>
<meta name="description" content="<?=$metadescription;?>" />
<meta name="keywords" content="<?=$metakeywords;?>" />
<link rel="stylesheet" type="text/css" href="/css/common/style.css" />
</head>
<body>
<div class="header">
header here
</div>
<div class="page-container">
<div class="main">
<?= $this->load->view($content_view) ?>
</div>
</div>
<div class="footer">
footer here
</div>
</body>
</html>
Homepage view (views/homepage.php) (note: I might not have this exactly right.. I'm typing in from memory, so the data references might need some help)
Code:
<div class="main-content">
<h1>This is a content title</h1>
<p>This is some content text</p>
<?php if ($content_data != ''): ?>
<ul>
<?php foreach($content_data as $row): ?>
<li><?=$row->field ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Good luck! Let me know if you have questions.