ErrorException(E_ERROR)HELP数组转换为字符串(视图:C:\ xampp \ htdocs \ blog50 \ app \ views \ blog \ view.blade.php)

时间:2017-07-17 09:53:30

标签: php laravel-5

//这是view.blade.php文件。它显示上述错误可以任何人请给出想法什么是错的。路线。 php文件和博客controller.php如下。 ,也许问题出在控制器或路径文件中,我不知道。

/// view.blade.php

@section ('content')

@include('blog.partials.post', array('post'=> $post))

<hr/>

<section id="comments">

@foreach($post->comments as $comment)

<div class="comment">
    <p>{{$comment->name }} says...</p>
    <blockquote>
        {{$comment->comment}}
    </blockquote>
</div>
@endforeach

</section>
<section>

<h3 class="title">Add a Comment..</h3>
<form action="{{ URL::route('createComment'), array('id'=>$post->id)}}" method="POST">
    <div class="form-group" >
        <input type="text" name="name" placeholder="your name" class="form-control">

    </div>
    <div class="form-group" >
        <textarea class="form-control" name="content" placeholder="your comment">
        </textarea>

    </div>
    <input type="submit" class="btn btn-primary" value="Add Comment">

</section>


@stop

/// route.php

  Route::get('/', 'BlogController@index');

Route::get('post/new', array(
    'uses'=>'BlogController@newPost',
    'as' =>'newPost',
    ));

Route::post('/post/new' ,array(

    'uses' =>'BlogController@createPost',
    'as' =>'createPost',
    ));

Route::get('post/{id}',array(

    'uses' =>'BlogController@viewPost',
    'as' =>'viewPost',
    ));

Route::post('/post/{id}/comment',array(
     'uses'=>'BlogController@createComment',
     'as' =>'createComment'
    ));

//// BlogController

class BlogController extends BaseController {

    // set this controller's layout
    protected $layout = 'layouts.master';

    public function index()
    {
        $this->layout->content = View::make('blog.index',array(
            'posts'=>Post::all()
            ));
    }

    // TODO: implement all the function we need in this controller

    public function newPost()

    {
         $this->layout->content = View::make('blog.new');


    }

    public function createPost()

    {

       $post= new Post();
       $post->title=Input::get('title');
       $post->content=nl2br(Input::get('content'));
       $post->save(); 

       return Redirect::route('viewPost', array('id'=>$post->id));

    }

    public function viewPost($id)

    {  
        $post = Post::findOrFail($id);

        $this->layout->content = View::make('blog.view',array(

             'post' =>$post
            ));

    }

    public function createComment($id)

    {  $post = Post::findOrFail($id);

       $Comment= new Comment();
       $Comment->name=Input::get('name');
       $Comment->content=nl2br(Input::get('content'));
       $post->Comments()->save();

       return Redirect::route('viewPost',array('id'=>$post->id));


    }

}

1 个答案:

答案 0 :(得分:0)

您的参数应该是这样的

<form action="{{ URL::route('createComment', array('id'=>$post->id))}}" method="POST">

注意: laravel刀片模板{{}}相当于echo所以现在您的传递参数在外面。所以它试图回应阵列。所以这里echo不能回显数组变量。这就是为什么它会给出这个错误。

  

数组到字符串转换