(10-25-2014, 06:35 AM)jlp Wrote: (10-22-2014, 12:48 AM)Tux Wrote: Load "header", "footer" and "content" all at same time by using simple "page()" function.
Site.php Model:
Code:
<?php defined('BASEPATH') OR exit('Access Denied');
class Site extends CI_Model {
function page($page, $data = NULL) {
$data['base'] = base_url();
$data['page'] = current_url();
$this->load->view('header', $data);
$this->load->view($page, $data);
$this->load->view('footer', $data);
} #page
} #class
#EOF: ./application/models/Site.php
Speaking as an educator, I see MVC as a design pattern to separate state from presentation from control, and I encourage my students not to mix things up.
For instance, if my students submitted work where one of their models loaded any view stuff, they would be penalized marks. Similarly, if they submitted work where a view component accessed a database, they would be penalized marks too.
To me, the proper place for the "page" method you show is in the controller. If this were something used frequently, I would go so far as to put it in a base controller (core/MY_Controller).
Just trying to encourage good practices!
I tend to agree with this. Why use the MVC method if it is not going to be followed? What it comes down to for me is clean code design. Your "Page" function is something I would put in my base controller.
This is certainly an excellent idea (and the same that I use), but in my opinion it is simply in the wrong place.