【问题标题】:PHP smarty variable errorPHP smarty变量错误
【发布时间】:2012-04-09 15:03:51
【问题描述】:

我有这个错误

“注意:未定义的变量:C:\WAMP\WWW\SITE\TOOLS\SMARTY\SYSPLUGINS\SMARTY_INTERNAL_DATA.PHP 中的 LOGO ON LINE 291 CALL STACK”

这是我的 PHP 代码

function hookFooter($params)
{
    global $smarty;
    $smarty->assign('ENT_QUOTES', ENT_QUOTES);
    if( file_exists('modules/ebbrandingfooter/logo-footer.jpg')){
        $smarty->assign('logo','modules/ebbrandingfooter/logo-footer.jpg');
    };
    $FOOTERdescription=Configuration::get('FOOTER_DESC');
    $smarty->assign('description',$FOOTERdescription );
    return $this->display(__FILE__, 'ebbrandingfooter.tpl');
}

这里是 TPL

  {if $logo}<img src="{$logo}" />{/if}
  <p>{$description}</p>

谁能帮助我做错了什么? 谢了!!!

【问题讨论】:

  • 您的 if(file_exists) 条件是否返回 true?如果没有,您的 logo var 分配将不会发生,然后您的 TPL 将调用一个不存在的 logo 变量。您已尝试通过说“if $logo”在 TPL 中解决它,但它仍在检查布尔值...您应该改用 if isset $logo

标签: php variables smarty


【解决方案1】:

您可以修改您的 PHP 代码以确保设置了 $logo,例如:

function hookFooter($params)
{
    global $smarty;
    $smarty->assign('ENT_QUOTES', ENT_QUOTES);
    if( file_exists('modules/ebbrandingfooter/logo-footer.jpg')){
        $smarty->assign('logo','modules/ebbrandingfooter/logo-footer.jpg');
    } else {
        $smarty->assign('logo', null);
    }
    $FOOTERdescription=Configuration::get('FOOTER_DESC');
    $smarty->assign('description',$FOOTERdescription );
    return $this->display(__FILE__, 'ebbrandingfooter.tpl');
}

另请注意,} 之后不需要分号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多