if语句中的Smarty调用对象方法

问题描述 投票:1回答:1

所以我试图将对象分配给smarty。

    $a = FrameworkCore::getUserSessionObj(); // returns the object ofc
    $smarty->registerObject('global_session',$a);



  {if $global_session->isLoggedIn eq true}
    LOGGED IN
  {else}
    NO
  {/if}

现在我正尝试将方法调用放入if语句中,但它将无法正常工作。使用不同的值和其他方法多次尝试。

方法调用的输出工作正常(请参见下文)。

  {global_session->getType}
  {global_session->isLoggedIn}

因此,似乎//我的失败在if语句中,但我无法使其正常工作。

php smarty
1个回答
0
投票

好像您需要在方法名称中添加括号,就像在PHP中一样。

{if $global_session->isLoggedIn()}
    LOGGED IN
{else}
    NO
{/if}
© www.soinside.com 2019 - 2024. All rights reserved.