简体   繁体   English

Laravel表单模型绑定htmlentities错误

[英]Laravel form model binding htmlentities error

I am trying to use form model binding (which i just learned about), but im following an example from laravel website and one from laracasts. 我正在尝试使用表单模型绑定(这是我刚刚学到的),但是我遵循的是laravel网站的示例和laracasts的示例。 So can someone please educate me? 那有人可以教育我吗?

My View: 我的观点:

{{ Form::model($transaction, array(
        'method' => 'PATCH',
        'route' => array('my.transactions.update', $transaction->id)
)) }}
<div class="form-group">
  <label class="col-md-2 control-label" for="date"></label>
  <div class="col-md-2">
    <div class="input-group">
    {{ Form::text('date', array('class'=>'form-control input-md', 'placeholder'=>'YYYY-MM-DD')); }}
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>
{{Form::close() }}

My Controller: 我的控制器:

public function edit($id)
{
    $title = "Edit Transaction";
    $transaction = Portfolio::find($this->portfolio_id)->transactions->find($id);
    return View::make('Transactions/edit', compact('title', 'transaction'));
}

i dont know whats wrong but i keep getting this error. 我不知道出了什么问题,但我不断收到此错误。

htmlentities() expects parameter 1 to be string, array given (View: ../transactions/edit.blade.php)

I figured it out. 我想到了。 It ws actually completely different. 它实际上完全不同。 But im not sure why... 但是我不确定为什么...

Problem Line: 问题专线:

{{ Form::text('date', array('class'=>'form-control input-md', 'placeholder'=>'YYYY-MM-DD')); }}

Correction: 更正:

{{ Form::text('date', '', array('class'=>'form-control input-md', 'placeholder'=>'YYYY-MM-DD')); }}

The second option you put as '' can be filled in as Input::old('date') That way, when you pass old data back to the form let's say when the form isn't completed, the form fields that you specify with the Input::old will be "refilled" with the data they previously completed 您可以将输入为''的第二个选项填写为Input :: old('date')这样,当您将旧数据传递回表单时,假设表单未完成时,您指定的表单字段使用Input :: old将会被他们先前完成的数据“重新填充”

{{ Form::text('date', Input::old('date'), $dateOptions) }} {{Form :: text('date',Input :: old('date'),$ dateOptions)}}

$dateOptions will be your array with the placeholder, id, or any other html attributes you wish to supply. $ dateOptions将是包含占位符,id或您希望提供的任何其他html属性的数组。

Hope this helps, even after you figure it out Keenan :) 希望这对您有所帮助,即使您弄清了基南:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM