Php 未定义变量:标题,以Laravel表示
我正在定义我的方法控制器index(),并传递参数title以在html视图中显示:Php 未定义变量:标题,以Laravel表示,php,laravel,Php,Laravel,我正在定义我的方法控制器index(),并传递参数title以在html视图中显示: class WebController extends BaseController{ public $layout = 'layout.base'; /*Index*/ public function index(){ $this->layout->title = 'Index Title'; return View::make('page
class WebController extends BaseController{
public $layout = 'layout.base';
/*Index*/
public function index(){
$this->layout->title = 'Index Title';
return View::make('pages.index');
}
}
但当我加载页面时,返回以下错误:
在我的“app\views\layout\base.blade.php”中,我有:
<!DOCTYPE html>
<html lang="es">
<head>
<title>{{$title}}</title>
@section('metas')
@show
@section('styles')
@show
</head>
如何解决这个问题?
多谢各位 试试这样的方法,返回View::make(…)时必须传递变量。 如果要传递更多变量,可以使用compact();功能
/*Index*/
public function index(){
$title = 'Index Title';
return View::make('pages.index', $title);
}
使用compact()的示例
尝试将包含数据的数组添加到
视图::make
:
return View::make('pages.index', array('title' => 'Title'));
试着写下你的观点
return View::make('pages.index');
到
您的索引控制器正在创建一个视图
pages/index.blade.php
,但是您显示了layout\base.blade.php
中的错误是的,它是有效的,但不存在最优雅的方法吗?
return View::make('pages.index', array('title' => 'Title'));
return View::make('pages.index');
return View::make('pages.index')->with('title', $this->layout->title);