【发布时间】:2014-03-21 02:23:16
【问题描述】:
我正在编写我的第一个 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'=>'HomeController@getInput'));
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);
【问题讨论】:
-
您的代码应该工作。我测试了它....(假设 die() 不在第一名)
标签: php forms laravel laravel-4 laravel-routing