Home  >  Article  >  Backend Development  >  在laravel中遇到compact(),对其中参数不理解

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

WBOY
WBOYOriginal
2016-06-06 20:41:182268browse

<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>

代码如上,其中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>

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

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

compact('comments')=$comments

Statement:
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