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

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

Make sure you autoload this "Site.php" model in your config. You need to edit "application/config/autoload.php" file and add "site" to model autoload array.

Usage in Controller:
Code:
<?php defined('BASEPATH') OR exit('Access Denied');

class Welcome extends CI_Controller {

    public function index() {
        $data['title'] = 'Welcome Page';
        $this->site->page('welcome', $data);
    } #index

} #class

#EOF: ./application/controllers/Welcome.php

header.php view:
Code:
<!DOCTYPE html>
<html lang="en">
    <head>
        <title><?=$title?></title>
        <meta charset="utf-8">
        <meta name="robots" content="all">
        <link rel="stylesheet" href="<?=$base?>/style.css">
    </head>
<body>

welcome.php view:
Code:
<div id="content">

  <h1> Example Welcome Page! </h1>

</div> <!--#content-->

footer.php view:
Code:
<div id="footer">
All rights reserved.
</div> <!--#footer-->
</body>
</html>
Angel
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