Laravel控制器不会传递变量进行查看

时间:2015-05-23 06:12:08

标签: php laravel laravel-blade

我看过一个关于Laravel的youtube教程。这是代码。我开始学习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后,出现错误,指出变量未定义。

1 个答案:

答案 0 :(得分:1)

试试这个..

<?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);
 }
}
?>