Laravel控制器不会将变量传递给view


Laravel controller doesn't pass the variables to view

我在youtube上看过一个关于Laravel的教程。这是代码。我开始学习Laravel。

 <?php
class Authors_Controller extends BaseController {
public $restful = true;
public function get_index(){
    $view = View::make('authors.index',array('name'=>'Jedi'))->with('age','18');
    $view->location='somewhere';
    $view['favorite'] = 'bacon';    
    return $view;
 }
}
?>

视图代码
<?
 php echo $name;
 echo $age;
 echo $location;
 echo $favorite;
?>

一旦我运行了localhost,我得到一个错误,声明变量是未定义的。

试试这个…

<?php
class Authors_Controller extends BaseController {
public $restful = true;
public function get_index(){
    $view = View::make('authors.index',array('name'=>'Jedi'))->with('age','18');
    $view->location='somewhere';
    $view['favorite'] = 'bacon';    
   return View::make('foldername/filename')->with('view',$view);
 }
}
?>