2014-02-20 25 views
0

我正在處理我的第一個laravel腳本,嘗試提交表單並在同一頁面上看到輸入。我正在解決這個問題好幾天,希望有人能解決這個問題。問題是,我得到這個錯誤:將輸入(表單)從頁面傳遞到自身

Undefined variable: data (View: D:\Programmer\wamp\www\laravel\app\views\bassengweb.blade.php) 

觀點:Bassengweb.blade.index

@extends('master') 

@section('container') 
<h1>BassengWeb testrun</h1> 
<table> 
{{ Form::open(array('route' => 'bassengweb', 'url' => '/', 'method' => 'post')) }} 
<tr> 
    <td>{{ Form::label('bassengId', 'Basseng ID')}}</td> 
    <td>{{ Form::text('bassengId') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::label('frittKlor', 'Fritt Klor')}}</td> 
    <td>{{ Form::text('frittKlor') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::label('bundetKlor', 'Bundet Klor')}}</td> 
    <td>{{ Form::text('bundetKlor') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::label('totalKlor', 'Total Klor')}}</td> 
    <td>{{ Form::text('totalKlor') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::label('ph', 'PH')}}</td> 
    <td>{{ Form::text('ph') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::label('autoPh', 'Auto PH')}}</td> 
    <td>{{ Form::text('autoPh') }}</td> 
</tr> 
<tr> 
    <td>{{ Form::submit('Lagre målinger') }}</td> 
{{ Form::close() }} 
</table> 


@if($data) 
    {{ $data->bassengId }} 
@endif 
@stop 

Homecontroller.php

<?php 

class HomeController extends BaseController { 

    public function showWelcome() 
    { 
     return View::make('hello'); 
    } 

    public function showTest() 
    { 
     return View::make('test'); 
    } 

    public function getInput() 
    { 
     $input = Input::all(); 
     print_r($input); die(); 
     return View::make('bassengweb')->with('data', '$input'); 
    } 
} 

觀點:master.blade.php

<div class="container"> 
    @yield('container') 
</div> 

routes.php

Route::get('/', function() 
{ 
    return View::make('bassengweb'); 
}); 

//Route::post('/', array('uses'=>'[email protected]')); 

Route::post('/',function(){ 
$input = Input::all(); 
//for inspecting input 
print_r($input); 
die(); 
//to send input to view but before sending to view comment last two lines 
return View::make('bassengweb')->with('data',$input); 
+0

代碼__should__工作。我測試了它....(假設_die()_不在第一位) – itachi

回答

0

你在單引號$輸入您的HomeController.php,而不是嘗試:

<?php 

class HomeController extends BaseController { 
public function showWelcome() 
{ 
    return View::make('hello'); 
} 

public function showTest() 
{ 
    return View::make('test'); 
} 

public function getInput() 
{ 
    $input = Input::all(); 
    print_r($input); die(); 
    return View::make('bassengweb')->with('data', $input); 
} 

}

+0

編輯它,但仍然得到det同樣的錯誤,加載視圖頁面時指定。 – user3185936

+0

$數據應該是一個數組,因此我會在您的視圖中嘗試{{$ data ['bassengId']}}。 –

+0

仍然無法正常工作。你有沒有嘗試過你的自我? – user3185936

0

在你routes.php,改變路線註冊了一點。

Route::get('/', function() 
{ 
    $data = Input::all(); 
    return View::make('bassengweb', compact('data')); 
}); 
相關問題