[英]“htmlentities() expects parameter 1 to be string, array given” in PHP
My problem seems to be with Laravel helpers. 我的问题似乎出在Laravel助手身上。 Everything was working fine until I change some files to other folders, of course I changed the routes and on routes and controllers but now I'm getting this message:
在我将一些文件更改为其他文件夹之前,一切工作正常,当然我更改了路由以及路由和控制器,但现在我收到以下消息:
ErrorException in HtmlBuilder.php line 65: htmlentities() expects parameter 1 to be string, array given (View: /Library/WebServer/Documents/gamstec/resources/views/posts/create.blade.php)
HtmlBuilder.php 65行中的ErrorException:htmlentities()期望参数1为字符串,给定数组(视图:/Library/WebServer/Documents/gamstec/resources/views/posts/create.blade.php)
This is my create file: 这是我的创建文件:
<div class="content">
<div class="container-fluid">
<div class="row well bs-component">
<div class="col-md-8 col-md-offset">
<div class="input-group">
<h3 class="text-center">Crear Nueva Publicación</h3>
<hr>
{!! Form::open(array('route' => 'posts.store', 'data-parsley-validate' => '')) !!}
{{ Form::label('title', ' Título:', array('class' => 'fa fa-pencil')) }}
{{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255')) }}
{{ Form::label('body', ' Contenido:', array('class' => 'fa fa-pencil-square-o')) }}
{{ Form::textarea('body', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::submit('Publicar', array('class' => 'btn btn-info')) }}
</div>
</div> <!-- col-md-8 end -->
<div class="col-md-4">
<div class="input-group">
<h3 class="text-center">Categoría e imágen</h3>
<hr>
<br> <hr>
{{ Form::label('badge', ' Etiqueta:', array('class' => 'fa fa-tags')) }}
{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
<br> <hr>
{{ Form::label('postimg', ' Seleccionar Imagen', array('class' => 'fa fa-picture-o')) }}
<br> <br>
{{ Form::file('postimg', array('require' => '', 'maxlength' => '255')) }}
{!! Form::close() !!}
</div> <!-- item-group end -->
</div> <!-- col-md-4 end -->
</div> <!-- end of row -->
</div> <!-- end of container -->
</div> <!-- end of content -->
This is my controller file: 这是我的控制器文件:
<?php
public function index()
{
return view('admin');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('posts.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// validate the data
$this->validate($request, array(
'title' => 'required|max:255',
'body' => 'required',
));
// store in database
$post = new Post;
$post->title = $request->title;
$post->body = $request->body;
$post->badge = $request->badge;
$post->postimg = $request->postimg;
$post->save();
Session::flash('success', 'La publicación se ha creado correctamente');
// redirect to another page
return redirect()->route('show', $post->id);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::find($id);
return view('show')->withPost($post);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
I'll be grateful for your help. 感谢您的帮助。
That's line generate the error: 那行会产生错误:
{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
You can pass an additional value option as a second argument can't be an array 您可以传递附加值选项,因为第二个参数不能是数组
To add other attributes, pass a third argument to the method. 要添加其他属性,请将第三个参数传递给该方法。 This third argument must be an array.
第三个参数必须是一个数组。
Change to this : 更改为:
{{ Form::text('badge', '', array('class' => 'form-control', 'maxlength' => '20')) }}
It's this line in your code: 这是代码中的这一行:
{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
It needs null as the second value: 它需要null作为第二个值:
{{ Form::text('badge', null, array('class' => 'form-control', 'maxlength' => '20')) }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.