htmlspecialchars()期望参数1是字符串,给定php的数组

时间:2017-04-03 07:51:53

标签: php arrays string

所以我试图在我的tpl中调用这个funktion但是我得到错误按摩: 注意:未定义的偏移量:第342行的/var/www/virtual/www.eless.de/ivanovm/lib/data/Contract.class.php中的1

警告:htmlspecialchars()要求参数1为字符串,数组在第135行的/var/www/virtual/www.eless.de/ivanovm/templates/compiled/d9e0e5ca75d171cae06b57137aa1475b7f24e533_2.file.contractList.tpl.php中给出 (第135行是空的)

public function getYearlyConsumption()
    {
        $yearlyConsumption = [];
        $idx = 0;

        //company bestimmen und zugehörige consumption points aufrufen
        $company = System::getUser()->getCompany();
        $consumptionPoints = $company->getConsumptionPoints();

        foreach ($consumptionPoints as $consumptionPoint) {
            if ($consumptionPoint->status == 1) {
                $yearlyConsumption[$idx] += $consumptionPoint->getYearlyConsumptionInt();
                $idx++;

            }
        }
        return $yearlyConsumption;
    }

这是我模板中的调用(这个错误会弹出我试图调用上面代码的每个功能只是一个例子

{foreach from=$data item=item}
                <tr>
                    <td>
                        <a href="{System::getLink('contractView')}"><input type="button" style="text-align: center"
                                                                           width="200em"
                                                                           value="&raquo;{$item->contractID}&laquo;"></a>
                    </td>
                    <td>
                        {$item->date|date_format:"%d.%m.%Y"}
                    </td>
                    <td>
                        {$item->selectedPrice}
                    </td>
                    <td>
                        {$item->getYearlyConsumption()}
                    </td>
                    <td>
                        {$item->getConsumptionPointsCount()}
                    </td>
                    <td>
                        {if $item->status == 0}
                            <span {literal}style="background-color:#ff9933"{/literal}>Wird Bearbeitet</span>
                        {/if}
                        {if $item->status == 1}
                            <span {literal}style="background-color:#33cc33"{/literal}>Abgeschlossen</span>
                        {/if}
                        {if $item->status == 2}
                            <span {literal}style="background-color:#ff0000"{/literal}>Stoniert</span>
                        {/if}
                    </td>
                </tr>
            {/foreach}

1 个答案:

答案 0 :(得分:0)

getYearlyConsumption()返回数组,并尝试将数组显示为包含在{}中的字符串。 {}标签调用htmlspecialchars()函数。