【发布时间】:2015-07-14 00:42:23
【问题描述】:
我正在尝试对每个页面进行分页 6 的最大结果。
这是我在控制器中的代码:
public function brand_new(Request $request)
{
$current_page = $request->get('page', 1);
$find_vehicles = $this->filterAll();//retrieving all the vehicles by calling a method
$total = $find_vehicles->count();
$paginator = new LengthAwarePaginator($find_vehicles, $total, 6, $current_page);
$paginator->setPath($request->getBasePath());
return view('pages.massSearch',compact('paginator'));
这是我在 *.blade.php 中的代码:
@foreach($paginator->getCollection()->all() as $pg)
{{ $pg->ImagePath }} {{--ImagePath is the php name of a table column--}}
@endforeach
但我收到错误:试图获取非对象的属性
任何建议都会有所帮助...
filterAll 方法:
public function filterAll($val)
{
$filter_avl = VehicleQuery::create()
->filterByAvailability(true)
->find();
$filter_modelAvl = VehicleQuery::create()
->useVModelQuery()
->filterByAvailability(true)
->endUse()
->find();
$filter_bndAvl = VehicleQuery::create()
->useVBrandQuery()
->filterByAvailability(true)
->endUse()
->find();
$filter_cStatus = VehicleQuery::create()
->useCurrrentStatusQuery()
->endUse()
->find();
$filter_mode = VehicleQuery::create()
->useVehicleModeQuery()
->filterByModeName($val)
->endUse()
->find();
$find_vehicles = VehicleImagesQuery::create()
->joinWith('VehicleImages.Vehicle')
->joinWith('Vehicle.VModel')
->joinWith('Vehicle.VBrand')
->joinWith('Vehicle.CurrrentStatus')
->joinWith('Vehicle.VehicleMode')
->filterByVehicle($filter_avl)
->filterByVehicle($filter_modelAvl)
->filterByVehicle($filter_bndAvl)
->filterByVehicle($filter_cStatus)
->filterByVehicle($filter_mode)
->find();
return $find_vehicles;
}//no errors with this code retrieve data perfectly.. Pagination part is the problem.
【问题讨论】:
-
请添加有关哪一行导致该错误的信息
-
使用
@foreach($paginator->getCollection() as $pg)而不是@foreach($paginator->getCollection()->all() as $pg) -
我认为是
{{$pg->ImagePath }}。如果我编码为{{ $pg->getImagePath() }}它会给我错误:调用数组上的成员函数 getImagePath()。 -
我试过
@foreach($paginator->getCollection() as $pg)。但是给出了保存错误。 -
当我尝试
{{ dd($pg) }}它返回array:1 [▼ 1790921346 => 0 ]
标签: php laravel pagination propel