Welcome Guest, Not a member yet? Register   Sign In
Multiple Pages (404 errors)
#13

[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">
&lt;html &gt;
&lt;head&gt;
    &lt;title&gt;&lt;?=$titletag;?&gt;&lt;/title&gt;
    &lt;meta name="description" content="&lt;?=$metadescription;?&gt;" /&gt;
    &lt;meta name="keywords" content="&lt;?=$metakeywords;?&gt;" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="/css/common/style.css" /&gt;
&lt;/head&gt;
&lt;body&gt;
<div class="header">
    header here
</div>
<div class="page-container">
    <div class="main">
        &lt;?= $this->load->view($content_view) ?&gt;
    </div>
</div>
<div class="footer">
    footer here
</div>
&lt;/body&gt;
&lt;/html&gt;

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>
    
    &lt;?php if ($content_data != ''): ?&gt;
        <ul>
        &lt;?php foreach($content_data  as $row): ?&gt;
            <li>&lt;?=$row->field ?&gt;</li>
        &lt;?php endforeach; ?&gt;
        </ul>
    &lt;?php endif; ?&gt;
</div>

Good luck! Let me know if you have questions.


Messages In This Thread
Multiple Pages (404 errors) - by El Forum - 08-22-2008, 09:16 AM
Multiple Pages (404 errors) - by El Forum - 08-22-2008, 02:28 PM
Multiple Pages (404 errors) - by El Forum - 08-22-2008, 04:08 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 12:19 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 05:12 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 05:19 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 05:20 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 05:32 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 06:57 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 07:13 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 07:25 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 08:59 PM
Multiple Pages (404 errors) - by El Forum - 08-23-2008, 09:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB