[英]Laravel 4 error: Undefined variable
我做了一個填充我的下拉框的列表查詢。 我已經在控制器部分嘗試了var_dump,但一切正常,但是每當我嘗試在刀片模板上調用函數時,都會向我返回錯誤:未定義變量:類別(視圖:C:\\ wamp \\ www \\ airlines \\應用程序\\意見\\內容\\ onewayflight.blade.php)
這里似乎是什么問題?
OnewayflightController.php
public function onewayflight()
{
$categories = DB::table('oneways')->lists('destination-from');
return View::make('content.onewayflight')->with('destination-from', $categories);
}
onewayflight.blade.php
{{ Form::select('destination-from', $categories) }}
routes.php文件
Route::get('flight/onewayflight','OnewayflightController@onewayflight');
您應該在Blade中使用:
{{ Form::select('destination-from', $destination-from) }}
因為在您的方法中,您使用了:
with('destination-from', $categories)
所以您告訴我們在Blade中, $categories
必須命名為$destination-from
但是,您不能在變量名中使用-
,因此您應該將其更改為:
with('destinationFrom', $categories)
在Blade中:
{{ Form::select('destination-from', $destinationFrom) }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.