Welcome Guest, Not a member yet? Register   Sign In
How to Add Dynamic Header and Footer
#13

(This post was last modified: 12-13-2022, 11:07 AM by jamesedger.)

(03-02-2018, 10:56 AM)superbrands Wrote: Here is my code: mini militia

controllers/Home.php


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Home extends CI_Controller {
    
    
public function __construct()
    {
        parent::__construct();
        $this->load->helper('url_helper');
    }
    
    
public function index()
    {
        if ( ! file_exists(APPPATH.'views/themes/default/templates/common/home.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        }
        
        $data
['title'] = "Home";
        
        $this
->load->view('themes/default/templates/common/header'$data);
        $this->load->view('themes/default/templates/common/home'$data);
        $this->load->view('themes/default/templates/common/footer'$data);
    }



views/themes/default/templates/common/header.php

PHP Code:
<!DOCTYPE html>
<
html>
<
head>
<
title>Title</title>
</
head>
<
body>
<
header>
    <div class="container"><?php echo $title?></div>
</header> 


views/themes/default/templates/common/home.php

PHP Code:
<div class="container">
    <h1><?php echo $title?></h1>
</div> 


views/themes/default/templates/common/footer.php


PHP Code:
<footer>
    <div class="container"><?php echo $title?></div>
</footer>
</body></html> 


Right now, it shows the text Home in each section (in header, in home, and in footer).

I want each page shows different titles (header shows text Header, home shows text Home, and footer shows text Footer).

How to achieve it? Thanks.

I think you should need to change some basic Home.php codes to solve this issue.
Reply


Messages In This Thread
RE: How to Add Dynamic Header and Footer - by jamesedger - 12-09-2022, 09:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB