2017-07-31 37 views
0

我有這個變量,應該在我的網址,但包括「。」 (點)。對不起,我還是在拉拉維爾noob。控制器使用變量返回視圖Laravel

預期結果爲localhost/myProject的/公/ VAR_NAME

Eror說
查看[.sampleVariable]未找到。

我行

return view('/'.$create->var_name)->compact('anotherVar','anotherVar'); 

和我的路線是
Route::get('{var_name}', '[email protected]');

+0

這些信息不足以說明問題的可能性。什麼是'$ create'?你的控制器動作是什麼樣子的?你對項目的根源有什麼看法? – fubar

+0

'$ create-> var_name'是什麼? –

回答

0

路線是

Route::get('/{var_name}', '[email protected]'); 

myController的

public function index($var_name) 
{ 
    return view('template.index', ['var_name' => $var_name])->compact('anotherVar','anotherVar'); 

} 
+0

template.index是什麼意思? – Ralph

+0

template.index - 是模板刀片文件 - \ resources \ views \ template \ index.blade.php –

+0

@Ralph它表示文件位於'resources/views/template/index.blade.php' – adelowo

0

試試下面的代碼。 您的控制器功能類似的代碼

public function index($var_name) 
{ 
    //Initiate your variable... 
    $anotherVar = ''; 

    //Replace 'BLADEFILENAME' to you want to execute blade file name... 
    return view('BLADEFILENAME', compact('var_name','anotherVar')); 
} 

你可以閱讀更多關於php compact()。您還可以從控制器傳遞變量值由wrapping the variable in curly braces

您的路線如下代碼查看:

Route::get('/{var_name}', '[email protected]'); 

現在你可以使用$var_name & $anotherVar到您的刀片文件。

相關問題