Lemon
Lemon

Reputation: 199

Laravel controller doesn't pass the variables to view

I have watched a youtube tutorial about Laravel. This is the code. I started studying 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;
 }
}
?>

view code

<?
 php echo $name;
 echo $age;
 echo $location;
 echo $favorite;
?>

Once I ran the localhost, I get an error that states that the variables are undefined.

Upvotes: 3

Views: 715

Answers (1)

Deenadhayalan Manoharan
Deenadhayalan Manoharan

Reputation: 5444

Try this..

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

Upvotes: 1

Related Questions