【问题标题】:Laravel - htmlentities() expects parameter 1 to be string, array givenLaravel - htmlentities() 期望参数 1 是字符串,给定数组
【发布时间】:2017-09-23 08:45:30
【问题描述】:

我的blade.php代码是:

{!! Form::input('text', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}

HtmlBuilder.php 代码是

public function escapeAll($value)
{
    return htmlentities($value, ENT_QUOTES, 'UTF-8');
}

错误信息是:

ErrorException in HtmlBuilder.php line 65:
htmlentities() expects parameter 1 to be string, array given (View: /home/seyali-02/dev/htdocs/scam/resources/views/dashboard/Scam/edit.blade.php)

我已经改变了blade.php

{!! Form::input('text','', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}

{!! Form::text('name', 'tactic[]', null, array('id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1')) !!}

还有text('text', .. 但是对我来说没有任何效果,并且会抛出与我上面提到的相同的错误.. 我已经解决了与此相关的所有类似问题,但这些答案都没有解决我的问题。所以请避免重复这个问题,给我清晰正确的解决方案..

【问题讨论】:

  • $value 变量的值是多少?如我所见,这是一个数组。你能告诉我们 var_dump($value) 吗?

标签: php html laravel laravel-5


【解决方案1】:

您将tactic[] 添加到作为数组的名称中,因此当您发布数据时,它将作为数组进行。要么删除它,要么在 php 最终使用 implode

【讨论】:

  • 你能告诉我如何使用 implode,因为我是 php 和 laravel 的初学者吗??
  • @ManiRaj 点击上述链接。
  • 谢谢,如果我遇到任何问题,我会检查并通知您..
  • 这里是一个简单的描述@ManiRaj,Implode可以带2个参数,第一个是Delimiter,第二个参数是Array,implode会简单地将array的元素连接起来形成一个字符串。例如。 $array = ['a','b','c']; echo implode('-', $array); 输出将是 a-b-c-d
【解决方案2】:

如果你想将输入作为一个数组,那么你可以使用这个代码

{!! Form::text('tactic[]',null,['id' => 'tactic', 'class' => ' form-control TabOnEnter', 'placeholder' => 'Tactics_1']) !!}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2017-05-17
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多