Smarty Object Function with Associative Array Unexpected “=>”, expected one of: “”,“” , “)”'

霸气de小男生 提交于 2019-12-24 13:29:45

问题


I am having a problem with Smarty passing a PDO Object to Smarty it just doesn't like =>. Is there a trick to get around this problem?

Here is he error:

{assign var='brgdatas' value="{$brgObj->fetchOneBrg(array('id'=>{$ststres[ststval].to_id}'))}"}" - Unexpected "=>", expected one of: "","" , ")

Here is the code I am working with:

{section name=ststval loop=$ststres}

{if $ststres[ststval].type == 2}

{assign var='brgdatas' value="{$brgObj->fetchOneBrg(array('id'=>{$ststres[ststval].to_id}'))}"}

The correct answer Update:

Is to add [] between the associative array and remove the quotes like so.

{assign var='brgdatas' value=$brgObj->fetchOneBrg(['id'=>$ststres[ststval].to_id])}

回答1:


Remove the last single apostrophe and the keys {} inside the value attribute

value="{$brgObj->fetchOneBrg(array('id'=>{$ststres[ststval].to_id}'))}"
       ^                                 ^                        ^  ^


来源:https://stackoverflow.com/questions/13894472/smarty-object-function-with-associative-array-unexpected-expected-one-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!