switch case调用undefined变量

时间:2014-02-07 18:02:27

标签: php html switch-statement

我对变量

有疑问
(define ('THIS_PAGE', basename($_SERVER['PHP_SELF']) );

我在我的网站中调用标题标签,如

<title> <?=$title?><?=SITE?></title>. 

Site常量显示正常,但$ title变量返回错误'&lt; br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Undefined variable: title in lt;b&gt;/Applications/MAMP/htdocs/scc/sccc_2014/_240php/05a_dynamicContentc/_inc/inc_header.php&lt;/b&gt;

在线

&lt;b&gt;6&lt;/b&gt;&lt;br /&gt; MAX-O-MATIC

显示在我的标题标签中。我在本地使用MAMP工作,但我认为这不是问题。我希望这只是一个错字,但我仍然很新,它可能是任何东西。

感谢任何帮助。 是的我之前尝试过研究解决方案,并花时间尝试调试。没有做适当的努力,我不会来这里寻求帮助。 谢谢

配置文件:

define ('SITE', 'MAX-O-MATIC'); //Name of Site

define ('THIS_PAGE', basename($_SERVER['PHP_SELF']) ); //Constant Current Page is X

switch(THIS_PAGE)
{
    //Set most likely scenario as the first to run
    case 'index.php' :
       $title = "Welcome" ;
       $banner = "Max-o-matic";
       break;

    case 'itc240.php' :
       $title = "ITC240 |" ;
       $banner = "Samples";
       break;

    case 'itc250.php' :
       $title = "ITC250 |" ;
       $banner = "Samples";
       break;

    default :
       $title = "";
       $banner = "Default Banner";
}

HEADER FILE:

<!DOCTYPE HTML>
<html>

<head>

    <title>
            <?=$title?><?=SITE?>
    </title>

测试页:

<?php
//itc240.php
include '_inc/inc_config.php';   //My arrays and stuff
include '_inc/inc_header.php';
?>

test Content</p>

<?php
include '_inc/inc_footer.php';
?>

1 个答案:

答案 0 :(得分:1)

你是如何加载该配置文件的?

在尝试输出$ title之前确保已加载。