public function getList()
{
$posts=\Posts::allPosts();
$this->layout->content=\View::make('admin.posts.list', $posts);
}
所以我送$posts
阵列我的看法,但我得到一个错误,当我尝试var_dump(...)
它,它不存在。查看::化妆不从控制器返回数据,查看
public function getList()
{
$posts=\Posts::allPosts();
$this->layout->content=\View::make('admin.posts.list', $posts);
}
所以我送$posts
阵列我的看法,但我得到一个错误,当我尝试var_dump(...)
它,它不存在。查看::化妆不从控制器返回数据,查看
你应该告知变量名刃:
public function getList()
{
$posts=\Posts::allPosts();
$this->layout->content=\View::make('admin.posts.list', array('posts' => $posts));
}
一个常见的成语使用$ data数组。
public function getList()
{
$data = array(
'posts' => Posts::allPosts(),
'morestuff' => $variable,
);
$this->layout->content=\View::make('admin.posts.list')->with($data);
}
在这里做最简单的事情可能是使用compact()
public function getList()
{
$posts = \Posts::allPosts();
$this->layout->content = \View::make('admin.posts.list', compact('posts'));
}
它确实基本相同array('posts' => $posts)