在laravel中遇到compact(),对其中参数不理解

WBOY
Release: 2016-06-06 20:41:18
Original
2267 people have browsed it

<code>public function listComment(){
        $comments=Comment::orderBy('id','desc')->paginate(10);
         $this->layout->title='Comment Listings';
         $this->layout->main=View::make('dash')->nest('content','comments.list',compact('comments'));
    }
</code>
Copy after login
Copy after login

代码如上,其中compact 参数 为什么是'comments'而不是$comments?

回复内容:

<code>public function listComment(){
        $comments=Comment::orderBy('id','desc')->paginate(10);
         $this->layout->title='Comment Listings';
         $this->layout->main=View::make('dash')->nest('content','comments.list',compact('comments'));
    }
</code>
Copy after login
Copy after login

代码如上,其中compact 参数 为什么是'comments'而不是$comments?

建议楼主多看看官方文档
http://php.net/manual/zh/function.compact.php

compact('comments')=$comments

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template