【发布时间】:2011-01-09 13:30:31
【问题描述】:
我使用 Smarty 来实现我的模板。这个PHP语句怎么写。
<?php if(empty($_GET['action'])) { echo class="current"; } ?>
【问题讨论】:
标签: php smarty template-engine
我使用 Smarty 来实现我的模板。这个PHP语句怎么写。
<?php if(empty($_GET['action'])) { echo class="current"; } ?>
【问题讨论】:
标签: php smarty template-engine
发明模板引擎是为了将业务逻辑(以及请求本身)与表示逻辑分开。模板引擎不应该处理 $_GET、$_POST、$_SESSION 等。
如果您需要根据 $_GET['action'] 做出决定 - 只需使用调节器 smarty 的 assign 从控制器传递它。
无论如何,如果您不希望您的代码更符合逻辑和更明显,您可以使用$smarty.get.action
{if empty($smarty.get.action)}class="current"{/if}
【讨论】:
$_GET['action'] = 'detail' 赋值 我写了:{if ($smarty.get.action='detail') class="current"{/if} 但我得到一个错误
{if ($smarty.get.action eq 'detail') class="current"{/if}
{if ($smarty.get.action=='details')} class="current"{/if} 什么是最好的 == 或 eq ?谢谢
eq。
像这样:
{if !isset($smarty.get.action)}class="current"{/if}
【讨论】:
if($_GET['action'] == 'open') {} 有手册或文档吗?
{if ($smarty.get.action=='details')} class="current"{/if} :)