Smarty Object Function with Associative Array Unex

2019-08-11 14:21发布

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])}

标签: php pdo smarty
1条回答
爷、活的狠高调
2楼-- · 2019-08-11 15:01

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

value="{$brgObj->fetchOneBrg(array('id'=>{$ststres[ststval].to_id}'))}"
       ^                                 ^                        ^  ^
查看更多
登录 后发表回答