![](/img/trans.png)
[英]PHP Warning htmlentities() expects parameter 1 to be string, array given
[英]“htmlentities() expects parameter 1 to be string, array given” in PHP
我的問題似乎出在Laravel助手身上。 在我將一些文件更改為其他文件夾之前,一切工作正常,當然我更改了路由以及路由和控制器,但現在我收到以下消息:
HtmlBuilder.php 65行中的ErrorException:htmlentities()期望參數1為字符串,給定數組(視圖:/Library/WebServer/Documents/gamstec/resources/views/posts/create.blade.php)
這是我的創建文件:
<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 -->
這是我的控制器文件:
<?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)
{
//
}
感謝您的幫助。
那行會產生錯誤:
{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
您可以傳遞附加值選項,因為第二個參數不能是數組
要添加其他屬性,請將第三個參數傳遞給該方法。 第三個參數必須是一個數組。
更改為:
{{ Form::text('badge', '', array('class' => 'form-control', 'maxlength' => '20')) }}
這是代碼中的這一行:
{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
它需要null作為第二個值:
{{ Form::text('badge', null, array('class' => 'form-control', 'maxlength' => '20')) }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.