2017-03-09 45 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

實際上這也適用於我,謝謝你兄弟 –

相關問題