将全局变量分配给索引

assign global variable into index

我需要将我生成的title who throw class代码传递给头文件

这是我的索引:

 require('files/inc/config.php');
require('files/assets/php/header.php');
require('files/libs/Plantilla.class.php');
$plantilla = new plantilla($serv,$user,$pass,$base,$url,$sitio);
$pagina = empty($_GET['pagina']) ? "inicio" : $general->limpiar($_GET['pagina']);
    switch ($pagina) {
            case 'blog':
            $ids = $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];
            echo $ids[0];  
            $tsTitle = $ids[1];
            break;
        default:
            echo $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];
            break;
    }
require('files/assets/php/footer.php');

变量 $tsTitle 显示在 header.php 和 footer.php

<?php
    $titulo = $tsTitle;
    ?>
<!doctype HTML>
<html lang="es">
<head>
  <title><?php echo $titulo;?></title>

我的问题是 $tsTitle 只显示在 footer.php 如何在两个文件中显示?

y 在一个案例中分配一个值 $tsTitle = $ids[1];不为空

你应该移动你的代码位置

require('files/inc/config.php');

require('files/libs/Plantilla.class.php');
$plantilla = new plantilla($serv,$user,$pass,$base,$url,$sitio);
$pagina = empty($_GET['pagina']) ? "inicio" : $general->limpiar($_GET['pagina']);
    switch ($pagina) {
            case 'blog':
            $ids = $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];
            echo $ids[0];  
            $tsTitle = $ids[1];
            break;
        default:
            echo $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];
            break;
    }
require('files/assets/php/header.php');
require('files/assets/php/footer.php');

稍微修改一下脚本。

require('files/inc/config.php');
require('files/libs/Plantilla.class.php');


$plantilla = new plantilla($serv,$user,$pass,$base,$url,$sitio);
$data_Holder = '';

$pagina = empty($_GET['pagina']) ? "inicio" : $general->limpiar($_GET['pagina']);
    switch ($pagina) {
            case 'blog':
            $ids = $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];

            $data_Holder = $ids[0];  

            $tsTitle = $ids[1];
            break;
        default:
            $data_Holder = $plantilla->docs($month,$view,$ref,$titles);
            $ref = $_GET['ref'];
            $month = $_GET['month'];
            $view = $_GET['view'];
            $titles = $_GET['titles'];
            break;
    }

require('files/assets/php/header.php');
echo $data_Holder;
require('files/assets/php/footer.php');