• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Pages (404 errors)

#11
[eluser]benaroia[/eluser]
Tell y'all what. I'll run through that whole user guide again and then get back to you. It's probably me trying to do everything backwards and inefficiently due to my "newness" to CI. Here's how I'm (in my head) breaking it down:

You have the model. Not quite sure what that does. Right now my model has a loadpage() function that loads a specific page and returns content to the controller which calls the appropriate views.

You have the controller that decides what page get's displayed. I was kinda passing that off to the model and using the controller to link the model with the view. Probably not a good thing?

You have the view which is responsible for all the front end content. The final html code getting displayed. I'm using that by giving it a $data array with content.

#12
[eluser]missionsix[/eluser]
[quote author="benaroia" date="1219559104"]Tell y'all what. I'll run through that whole user guide again and then get back to you. It's probably me trying to do everything backwards and inefficiently due to my "newness" to CI. Here's how I'm (in my head) breaking it down:

You have the model. Not quite sure what that does. Right now my model has a loadpage() function that loads a specific page and returns content to the controller which calls the appropriate views.

You have the controller that decides what page get's displayed. I was kinda passing that off to the model and using the controller to link the model with the view. Probably not a good thing?

You have the view which is responsible for all the front end content. The final html code getting displayed. I'm using that by giving it a $data array with content.[/quote]


Controllers determine the page / page content. Model's interact with data. Views display data.



index.php routes to the right controller > method (page) depending on the URL. So index.php/controller_name/method_name/ is the what you base your page structures on. The method would then call the associated model's to build a page. From there the data returned from the models is passed to the view.

There is more to it but that's basically how it works.

#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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.