Php Laravel错误FatalErrorException语法错误,意外'$内容';(T_变量)
我是拉雷维尔的新手。 我想在Route::get之外创建页面内容,如下所述,然后从Route::get内部调用变量Php Laravel错误FatalErrorException语法错误,意外'$内容';(T_变量),php,Php,我是拉雷维尔的新手。 我想在Route::get之外创建页面内容,如下所述,然后从Route::get内部调用变量 $content='This is our contact page'; Route::get('/contact', function($contentDetail=$content){ return $contentDetail; }); 但是我得到了错误 FatalErrorException 语法错误,意外的“$content”(T_变量) 请告诉我如何做
$content='This is our contact page';
Route::get('/contact', function($contentDetail=$content){
return $contentDetail;
});
但是我得到了错误
FatalErrorException
语法错误,意外的“$content”(T_变量)
请告诉我如何做我想做的事。你可以这样写:-
Route::get('/contact', function(){
$content='This is our contact page';
return $content;
});
像这样使用Use($content)
在回调中传递变量$content
$content='This is our contact page';
Route::get('/contact', function()use($content){
return $content;
});
在回调函数中,它检查并获取url参数的值,如url/contact/{id?}
回调函数中的第一个参数将从url中获取id
的值,如果未找到,则将其设置为5
Route::get('/contact/{id?}', function($id=5){
return "id : ".$id;
});
谢谢你的回复。我希望变量来自函数外部。我不想在变量中声明它这是基本的php语法。例3