Welcome Guest, Not a member yet? Register   Sign In
Basic Page Function
#7

(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!
James Parry
Project Lead
Reply


Messages In This Thread
Basic Page Function - by Tux - 10-22-2014, 12:48 AM
RE: Basic Page Function - by Rufnex - 10-22-2014, 01:27 AM
RE: Basic Page Function - by John_Betong - 10-22-2014, 06:16 AM
RE: Basic Page Function - by John_Betong - 10-22-2014, 06:20 AM
RE: Basic Page Function - by Rufnex - 10-22-2014, 09:45 AM
RE: Basic Page Function - by navotjer - 10-24-2014, 04:29 AM
RE: Basic Page Function - by jlp - 10-25-2014, 06:35 AM
RE: Basic Page Function - by puppy - 11-04-2014, 08:11 AM
RE: Basic Page Function - by kilishan - 10-25-2014, 08:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB