[英]Laravel View Composer “Use of undefined constant”
整個晚上一直在尋找,這一切看起來都那么容易和簡單,但只是不起作用!
剛剛開始嘗試將變量放入視圖中。
無論我做什么,我似乎無法閱讀它。
routes.php文件:
Route::get('/', function()
{
return View::make('dashboard');
});
View::composer('dashboard', function($view) {
$view->with('links', "something");
});
dashboard.blade.php:
@extends('base_view')
@section('content')
All the stuff!
{{links}}
@stop
base_view.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
</head>
<body>
<div>TeamPro</div>
<div>@yield('content')</div>
</body>
</html>
請告訴我,我只是在做一些愚蠢的事情!
使用$links
,而不是links
:
@section('content')
All the stuff!
{{ $links }}
@stop
PHP中的每個變量都應以$
符號開頭。 如果沒有$
,PHP將其視為常量。
這只是一個簡單的語法問題,你發送到視圖的所有內容都是一個php變量,所以仍然需要用$
引用
在您的視圖中,您引用的是沒有美元符號的links
。
如果您將其更新為:
{{ $links }}
你會好的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.