我有一个可用性日历,我正在尝试使用Laravel发布到我的数据库。当我转出我的POST时,我得到了这个......
string(1440) "s:1430:"2012-11-06;;1;;888,2012-11-07;;1;;888,2012-11-08;;
1;;888,2012-11-09;;1;;888,2012-11-10;;1;;888,2012-11-11;;1;;888,2012-11-12;;
1;;888,2012-11 13;;1;;888,2012-11-14;;1;;888,2012-11-15;;1;;888,2012-11-16;;1;;
888,2012-11-17;;1;;888,2012-11-18;;1;;888,2012-11-19;;1;;888,2012-11-20;;1;;888,
2012-11-21;;1;;888,2012-11-22;;1;;888,2012-11-23;;1;;888,2012-11-24;;1;;888,
2012-11-25;;1;;888,2012-11-26;;1;;888,2012-11-27;;1;;888,2012-11-28;;2;;0,array(1)
{["availability"]=>string(973) "s:964:"2012-11-05;;1;;888,2012-11-29;;1;;
888,2012-11-30;;1;;888,array(1) {["availability"]=>string(12) "availability"}
<html><h2>Unhandled Exception</h2><h3>Message:</h3><pre>Error rendering view:
[layouts.admin] Undefined variable: title</pre><h3>Location:</h3>
<pre>/Users/corymjacik/Sites/shipwatch_v2.1/storage/views/33f72cb6519c7f146dc8d6af4b948300 on line 5</pre><h3>Stack Trace:</h3>
<pre>#0 /Users/corymjacik/Sites/shipwatch_v2.1/laravel/laravel.php(40):
Laravel\Error::native(8";"}
<html><h2>Unhandled Exception</h2><h3>Message:</h3>
<pre>Error rendering view: [layouts.admin]Undefined variable: title</pre>
<h3>Location:</h3>
<pre>/Users/corymjacik/Sites/shipwatch_v2.1/storage/views/33f72cb6519c7f146dc8d6af4b948300
on line 5</pre><h3>Stack Trace:</h3> <pre>#0 /Users/corymjacik/Sites/shipwatch_v2.1/laravel/laravel.php(40):
Laravel\Error::native(8";"
可能导致此错误的原因,以及为什么它包含在我的数据库POST中?下面是我的控制器代码。一切都很好,就像这样。我能够将该字符串发布到数据库(我使用serialize()将其转换为数组中的字符串)我也可以从数据库中获取它并且它在前端显示就好了。这些错误似乎没有什么区别,但我觉得我做的事情有些不对。
public function post_availability_save()
{
$availability = serialize(Input::get('dop_booking_calendar'));
//var_dump($availability);die;
$id = Auth::user()->id;
Availability::update($id, array(
'user_id' => Auth::user()->id,
'availability' => $availability
));
return Redirect::to('admin');
}
public function get_availability_load()
{
$id = Auth::user()->id;
$availability = array(
'availability' => Availability::find($id)->availability
);
var_dump($availability);
}
修改 更多地了解它,它也倾销了我的html布局的开头...... 谁知道是什么原因导致的?我会深入挖掘一下。 编辑 11/13/12
//*This is what ends up in my database (Type:TEXT) //
,2012-11-13;;1;;1,2012-11-14;;1;;1,2012-11-15;;1;;1,2012-11-16;;1;;1,2012-11-
17;;1;;1,2012-11-18;;1;;1,2012-11-19;;1;;1,2012-11-20;;1;;1,2012-11-21;;1;;1,2012
-11-22;;1;;1,2012-11-23;;1;;1,2012-11-24;;1;;1,2012-11-25;;1;;1,2012-11-26;;1;;1,
2012-11-27;;1;;1,2012-11-28;;1;;1,Array
(
[availability] => 1
)
<html><h2>Unhandled Exception</h2>
<h3>Message:</h3>
<pre>Error rendering view: [layouts.admin] Undefined variable: title</pre>
<h3>Location:</h3>
<pre>/Users/cory/Sites/shipwatchpoint_v2.1/storage/views/e2b30637bfaa9d210e31baf35870d230 on line 5</pre>
<h3>Stack Trace:</h3>
<pre>#0 /Users/corymjacik/Sites/shipwatchpoint_v2.1/laravel/laravel.php(40): Laravel\Error::native(8
// *layouts.admin.blade.php //
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ $title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- CSS -->
{{ HTML::style('css/bootstrap.css') }}
{{ HTML::style('css/jquery.dop.BookingCalendar.css') }}
{{ HTML::style('css/app.css') }}
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="shortcut icon" href="/img/ico/favicon.ico">
</head>
<body>
<div class="container-fluid">
{{ $content }}
</div>
<!-- JS -->
<!-- Placed at the end of the document so the pages load faster -->
{{ HTML::script('http://code.jquery.com/jquery-1.8.2.min.js') }}
{{ HTML::script('js/bootstrap.js') }}
{{ HTML::script('js/app.js') }}
{{ HTML::script('js/jquery.dop.BookingCalendar.js') }}
</body>
</html>
//*admin controller (public restful is set to true)//
public function get_index()
{
$id = Auth::user()->id;
$unit = array(
'unit' => Unit::find($id),
'unit_admin' => Unit::find($id)->user,
//'availability' => Availability::all() added this and it still showed errors
);
//var_dump($unit);die;
$this->layout->title = 'Admin Profile';
$this->layout->nest('content', 'admin.index', $unit);
}
public function post_availability_save()
{
//$availability = serialize(Input::get('dop_booking_calendar'));
$availability = Input::get('dop_booking_calendar');
//var_dump($availability);die;
$id = Auth::user()->id;
Availability::update($id, array(
'user_id' => Auth::user()->id,
'availability' => $availability
));
return Redirect::to('admin');
}
public function get_availability_load()
{
$id = Auth::user()->id;
$availability = array(
'availability' => Availability::find($id)->availability
);
var_dump($availability);
}
答案 0 :(得分:2)
return Redirect::to('admin');
发送标题&#39;在$ title中或在布局中设置它就像在action_index()
中一样return Redirect::to('admin')->with('title','supercooltitle');
或
return Redirect::to('admin')->with_title('supercooltitle');
然后你的视图可以获取$ title并退出显示未定义的引用。
其他选项是在布局上设置它类似于您对索引所做的操作。
答案 1 :(得分:0)
好的。所以,我终于明白了。错误是在帖子中发送的,因为我是var_dump'ing我们被选中的结果。我通过'die'和'json_encode'修复它。 感谢所有帮助过的人!