• 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Add Dynamic Header and Footer

(03-02-2018, 03:35 PM)wallacesilva09 Wrote: I solved this problem with MY_Controller.php in folder app/core/ I created a method/action with this:

PHP Code:
public function theme($file){

in controller extends the MY_Controller and call view with
PHP Code:

see more about MY_Controller here: https://www.codeigniter.com/user_guide/g...asses.html

I believe that it is necessary to explain something before showing the method I use. I started with CI2 and had close to zero knowledge of PHP. Then version 3.0 emerged, and I found myself at a crossroads: either I dived deep into learning CI or PHP, but it soon became clear that only the last option, PHP would be adequate. CodeIgniter is a powerful productivity tool, without a doubt, the better I understand it, the higher my productivity will be, but there is a limit. With each new version, some things stop being used and new ones appear. Most importantly, it is a tool designed with PHP in mind, not the other way around.

My knowledge of PHP remains close to zero, but it is my priority and where should I find solutions to problems, regardless of the framework used or even without any. I say this because I see that when faced with a problem whose solution is up to PHP, the solution is sought in the framework, CI.

New version .... New framework ... Wildlife, without framework ...
The solution I use (on the home page):

PHP Code:
$header = array ( 
'icon' => 'favicon'
'css' => 'home',
'title' => 'wdeda | Music, videos, blog',
'action' => '/lab/search/allmedia/',
'placeholder' => 'Search'

sometimes it´s very, very complex:

PHP Code:
foreach ($this->album_model->get_name() as $row); 
$playerid $row->id;
$name $row->name;
$this->album_model->get_album() as $row);
$rectitle $row->title;
$name1 $row->name1;
$name2 $row->name2;
$name3 $row->name3;
$name4 $row->name4
$names[0] = $name1;
$names[1] = $name2;
$names[2] = $name3;
$names[2] = $name4;
$print_name "";
 if( empty(
$name1) )
    $print_name $name;
    foreach( $names as $n )
        if( !empty($n) )
            if( $print_name != "" )
                $print_name .= " / ";
            $print_name .= $n;
$header = array ( 
'title' => $rectitle.' - '.$print_name' | Music | Credits | wdeda',
'icon' => 'favicon',
'css' => 'record',
'action' => '/lab/search/allmedia/',
'placeholder' => 'search'

And, of course, a single header meets every need.

PHP Code:
meta charset="UTF-8">
meta name="viewport" content="width=device-width, initial-scale=1.0">
meta name="description" content="Catálogo privado de filmes e músicas">
meta http-equiv="X-UA-Compatible" content="ie=edge">
link rel="shortcut icon" href="/lab/public/img/<?php echo $icon; ?>.ico" type="image/x-icon" />
link rel="stylesheet" href="/lab/public/css/global.css">
link href="/lab/public/css/header.css" rel="stylesheet">
link href="/lab/public/css/<?php echo $css; ?>.css" rel="stylesheet">
title><?php echo $title?></title>

<div class="search-container">
 <form action="<?php echo $action?>" class="site-search" method="post" name="site-search">
 <input class="site-search-button" name="submit1" type="submit" />
 <input class="site-search-input" name="search" placeholder="<?php echo $placeholder?>" tabindex="1" type="search" />

I have a blog, the placeholder will be ... Search the blog;
A specific area to search for backups, the placeholder will be .. Search backups

No matter which framework or its version, it is a solution, I can say, definitive.
It is important to consider that anyone who knows PHP will be able to analyze and, if applicable, make changes. Meets documentation requirements for systems and procedures.
OK, I'm not a professional, but nothing stops me from trying to think like one.

Why do not you use ajax to load the content? Insert this script inside the head tags and the file should load.

type: "GET",
url: "header/footer/header.html",
dataType: "html",
success: function(answer) {
error: function(){
alert("failed call!!!");
return false;

Omegle Bazoocam Chatrandom

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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