好的,我有一些PHP代码,但最近我改成了smarty。我想知道如何将PHP代码转换为智能代码。
PHP代码
<?php
if (isset($_SESSION['user']['id']))
{
echo "You are logged in using method 1";
}
if (Users::isuser())
{
echo "You are logged in using method 2
}
?>我到目前为止的尝试
{if isset($_SESSION['user']['id'])} You are logged in using method 1 {/if}
{if Users::isuser } You are logged in using method 2 {/if}但是他们的展台失败了?请帮帮我!
发布于 2014-05-10 05:17:04
你不需要,也不应该把所有的东西都转换成聪明的。
在PHP中,你应该这样做:
<?php
$smarty->assign('logged_method',0);
$smarty->assign('logged_method_2',0);
if (isset($_SESSION['user']['id']))
{
$smarty->assign('logged_method',1);
}
if (Users::isuser())
{
$smarty->assign('logged_method_2',1);
}
?>在Smarty中,你应该这样做:
{if $logged_method eq 1} You are logged in using method 1 {/if}
{if $logged_method_2 eq 1} You are logged in using method 2 {/if}Smarty应该仅用于显示数据,您不应该为smarty分配所有任务(例如,仅将comples变量/objest分配给进行简单比较)
顺便说一句,我不知道你想不想在代码中使用id,所以我保留了所有的代码不变,并引入了两个聪明的变量
https://stackoverflow.com/questions/23573338
复制相似问题