我正在尝试在 Laravel 4 中的控制器和视图文件之间使用对象数组。
控制器代码:
public function addItem()
{
$file = Input::file('file'); // your file upload input field in the form should be named 'file'
$destinationPath = 'uploads/'.str_random(8);
$filename = $file->getClientOriginalName();
//$extension =$file->getClientOriginalExtension(); //if you need extension of the file
$uploadSuccess = Input::file('file')->move($destinationPath, $filename);
$item = new Item();
$item->name = Input::get('item_name');
$item->description = Input::get('item_description');
$item->price = Input::get('item_price');
$item->picture_url = $destinationPath ."/". $filename;
$item->id_sale = Session::get('current_sale')->id;
$item->save();
$array_items = Session::get('current_items');
//$array_items = array($item);
array_push($array_items, $item);
//$array_items = array_add($array_items, $item->id, $item);
Session::put('current_items', $array_items);
//print_r(Session::get('current_items'));exit();
return Redirect::to('create_sale_add_item');
}
在此处查看代码“create_sale_add_item”:
@foreach(Session::get('current_items') as $i)
<div class="row">
<div class="span2"><h2><img src="{{ $i->picture_url }}" style="width: 200px; height: 150px;"></h2></div>
<div class="span10">
<p>Nom : {{ $i->name }}</p>
<p>Description : {{ $i->description }}</p>
<p>Prix : {{ $i->price }}</p>
</div>
</div>
@endforeach
但是当我显示相应的页面时,我有这个错误:
ErrorException
main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Item" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition
有人已经看到这个问题了吗?