【问题标题】:What's the issue in this smarty code?这个聪明的代码有什么问题?
【发布时间】:2013-06-12 07:43:18
【问题描述】:

我无法理解以下 smarty 代码中的问题?

<select class="list_items" name="staff_id" id="staff_id">
                  <option value="">All</option>
                    {if $staff_details}
                      {foreach from=$staff_details item=$staff_info}
                  <option value="{$staff_info.staff_id}"  {if $staff_id==$staff_info.staff_id} selected="selected"{/if}>{$staff_info.staff_full_name}</option>
                      {/foreach}
                    {/if}  
                  </select>

分配的$staff_details数组如下:

Array
(
    [staff_id] => ff8d4a5ea6bf11dce105aa2fa7b959b8
    [staff_type_id] => 2
    [staff_full_name] => Chetan G
    [staff_email] => admin@gmail.com
    [staff_password] => 123456
    [staff_status] => enable
)

它给了我错误:

Fatal error: Smarty error: [in chapter-mcq-questions.tpl line 45]: syntax error: 'foreach: 'item' must be a variable name (literal string) (SmartyCompiler.php, line 1183) in /var/www/schooling_needs/core/libs/Smarty.php on line 1095 

【问题讨论】:

    标签: foreach smarty


    【解决方案1】:

    而不是

    {foreach from=$staff_details item=$staff_info}
    

    {foreach from=$staff_details item=staff_info}
    

    【讨论】:

    • 感谢您的回答,它对我有用,但是当我通过 foreach 数组时,它只给我每个数组元素的第一个字母。实际上我想要一个完整的价值,例如员工全名来自数组。你能帮我弄到这个吗?再次感谢。
    • 好吧,如果你把你的数组变成这样的东西Array ( [0] =&gt; array ( [staff_id] =&gt; ff8d4a5ea6bf11dce105aa2fa7b959b8 [staff_type_id] =&gt; 2 [staff_full_name] =&gt; Chetan G [staff_email] =&gt; admin@gmail.com [staff_password] =&gt; 123456 [staff_status] =&gt; enable ) ) 它应该可以工作,但现在你不要' ahve 你试图寻找的键,以便更容易看到只是 echo $staff_info
    • 是的,你是对的,但我是 smarty 的新手,你能帮我用这种方式创建数组吗?
    • 对不起,我从来没有用过 smarty,所​​以我真的不知道怎么做,但我猜你可以在 google 上很快找到它;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 2014-08-29
    • 2013-06-05
    • 2014-06-04
    • 2011-07-07
    • 1970-01-01
    相关资源
    最近更新 更多