MVC Hierarchy question.

#8
[eluser]John_Betong[/eluser]
Hi Smalter,

The way I understand MVC is that the Controller's job is to gather data and to distribute the data to the views.

Can you try this approach to your existing code then edit __header.php, __content.php and __footer.php separately.

// Shop: Main Controller
Code:
class Shop extends Controller {
  function shop {
    parent::Controller();
    // Load somes library, plugins or helper
    $this->load->helper('blabla');
    $this->load->library('blabla');
    $this->load->model('my_model');
  }

  function index() {

    $data['htmltitle']    = 'This is my shop!';
    $data['list_item']    = $this->my_model->lastentries();

    $data['header']       = $this->load->view('__header',             $data, TRUE) ;
    $data['content']      = $this->load->view('__content_of_my_page', $data, TRUE);
    $data['footer']       = $this->load->view('__footer',             $data, TRUE);

    $output = $this->load->view('homepage',                           $data, TRUE);
    echo $output;
  }

}
 

// Homepage.php: Main view
Code:
<?= $header ?>
  <body style='background:#000 none; color:#fff'>

     <div style='background:#ff0 none; color:#f00; width:80%; margin:2em auto'>

       &lt;?=$content ?&gt;

       &lt;?=$footer ?&gt;

    </div>

&lt;/body&gt;
&lt;/html&gt;
&nbsp;

__header.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html lang="en-GB"&gt;
&lt;head&gt;
  &lt;title&gt;&lt;?= isset($debug) ? $debug : $htmltitle ?&gt;&lt;/title&gt;
&lt;/head&gt;
&nbsp;

__content.php
Code:
<h1>Content goes here</h1>
<pre>
&lt;?= print_r($data) ?&gt;
</pre>
&nbsp;

__footer.php
Code:
<h1>Footer goes here</h1>
<pre>
&lt;?= print_r($data) ?&gt;
</pre>


Cheers,

John_Betong
&nbsp;


Messages In This Thread
MVC Hierarchy question. - by El Forum - 12-25-2007, 05:52 PM
MVC Hierarchy question. - by El Forum - 12-25-2007, 10:38 PM
MVC Hierarchy question. - by El Forum - 12-26-2007, 02:13 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 04:12 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 04:25 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 05:26 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 09:03 PM
MVC Hierarchy question. - by El Forum - 12-26-2007, 11:59 PM
MVC Hierarchy question. - by El Forum - 12-30-2007, 05:30 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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