2017-03-09 47 views
1

我的问题似乎与Laravel助手。一切工作正常,直到我一些文件更改到其他文件夹,当然我改变了路线和路线上和控制器,但现在我得到这个消息:“htmlentities()期望参数1是字符串,数组给定”在PHP中

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)

这是我创建的文件:

<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) 
{ 
    // 
} 

我会是你的帮助表示感谢。

+0

你没有显示'HtmlBuilder .php第65行“,但在那里有一个到'htmlentities()'的调用,并且你正在传递一个数组。 – AbraCadaver

+0

抱歉为,这是在该行65 HtmlBuilder.php 公共函数escapeAll($值) { 返回ヶ辆($值,ENT_QUOTES, 'UTF-8'); } –

+0

所以你必须追查它。代码中的某些内容会调用其他最终调用'escapeAll()'的东西。在'htmlentities()'之前使用'debug_print_backtrace()'来查看它来自哪里。 – AbraCadaver

回答

2

这就是线生成错误:

{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }} 

可以传递一个额外值选项作为第二个参数不能是一个数组

要添加其他属性,传递第三个参数的方法。这第三个参数必须是一个数组。

改成这样:

{{ Form::text('badge', '', array('class' => 'form-control', 'maxlength' => '20')) }} 
+0

谢谢!它就像一个魅力! –

+0

如果这个答案解决了您的问题,请尝试使用旧的('徽章')而不是''来预填充值,如果表单中有错误 – Brett

+0

@JuanRincón如果此答案解决了您的问题,请考虑通过单击向下箭头下的勾选标记来接受该问题。这将问题标记为“已解决”并授予解决问题的回答者。 – Daedalus

0

这是这一行代码:

{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }} 

它需要null作为第二个值:

{{ Form::text('badge', null, array('class' => 'form-control', 'maxlength' => '20')) }} 
+0

实际上这也适用于我,谢谢你兄弟 –

相关问题