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

(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){
 
   $this->load->view('themes/default/templates/common/header'$data);
 
   $this->load->view('themes/default/templates/common/'.$file$data);
 
   $this->load->view('themes/default/templates/common/footer'$data);
}
//... 

in controller extends the MY_Controller and call view with
PHP Code:
$this->theme('home'); 


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):

Controller:
PHP Code:
$header = array ( 
 
'icon' => 'favicon'
 
'css' => 'home',
 
'title' => 'wdeda | Music, videos, blog',
 
'action' => '/lab/search/allmedia/',
 
'placeholder' => 'Search'
 
); 
 
 
$this->load->view('templates/header'$header);
 
$this->load->view('/home/home'$data); 
 
$this->load->view('templates/footer'); 

sometimes it´s very, very complex:

PHP Code:
foreach ($this->album_model->get_name() as $row); 
 
$playerid $row->id;
 
$name $row->name;
 
 foreach(
$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;
 }
 else
 {
    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'
 
); 
 
 
$this->load->view('templates/header'$header); 
 
$this->load->view('content/albums/album'$data);
 
$this->load->view('templates/footer'); 

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

PHP Code:
<head>
<
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>
</head>
...

<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" />
 </form>
 </div> 

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.
Reply


Messages In This Thread
RE: How to Add Dynamic Header and Footer - by wdeda - 02-20-2020, 05:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB