欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Cannot access protected property Illuminate\Pagination\LengthAwarePaginator::$currentPage total 有大用

$total 是受保护的变量 是使用 ->total()方法  来代替 ->total 这个变量吧
controller.php

public function index(){$ search = \ Request :: get('search'); $ pageRow = \ Request :: get('pageRow'); $ pageRow =($ pageRow)?$ pageRow:config('app.nbrPages.pageCnt');

  //$createdRits = $this->model->getSubmittedRits('supervisor',$pageRow,$search);

  $allEmpPeInfo = $this->model->getEmployePeInfo($pageRow,$search);

  $currentPage = $allEmpPeInfo->currentPage;
 $pageLimit = $allEmpPeInfo->perPage;
 $showingStartCnt = ($pageLimit * ($currentPage-1))+1; 
 $showingTotalLimit =$allEmpPeInfo->total;
 $showingEndLimit = $showingStartCnt+$pageLimit-1;
 $showingEndLimit = ($showingEndLimit > $showingTotalLimit) ? $showingTotalLimit : $showingEndLimit;



 $resultArr = array_merge(array('allEmpPeInfo' => $allEmpPeInfo), array('pageRow' => $pageRow), array('search' => $search) , array('pageRowsArr' => array(1,5,10,20,30,40,50)),array('currentPage' => $currentPage,'pageLimit' => $pageLimit, 'showingTotalLimit' => $showingTotalLimit,'showingStartCnt' => $showingStartCnt,'showingEndLimit' => $showingEndLimit));

  

    return view('performanceevaluation/index',compact('resultArr'));

}

model.php

public function getEmployePeInfo($ pageRows = 2,$ searchkey =''){

$getEmpInfo = $this->cssritDb->table('css_emp_pe_info')
  ->select('css_emp_pe_info.employee_number','css_emp_pe_info.emp_first_name','css_emp_pe_info.emp_last_name','css_emp_pe_info.pay_title','css_emp_pe_info.branch_org_mem_nm','css_emp_pe_info.div_org_mem_nm','css_emp_pe_info.current_pe_start_date','css_emp_pe_info.current_pe_end_date','css_emp_pe_info.next_pe_start_date','css_emp_pe_info.next_pe_end_date','css_emp_pe_info.pe_type','css_emp_pe_info.pe_rating');

 

// return $getEmpInfo->get();









if($searchkey)
    {


 $getEmpInfo = $getEmpInfo->where("(css_emp_pe_info.employee_number LIKE '%$searchkey%' OR css_emp_pe_info.emp_first_name LIKE '%$searchkey%' OR css_emp_pe_info.emp_last_name LIKE '%$searchkey%' OR css_emp_pe_info.pay_title LIKE '%$searchkey%' OR css_emp_pe_info.branch_org_mem_nm LIKE '%$searchkey%' OR css_emp_pe_info.div_org_mem_nm LIKE '%$searchkey%')");
        //$query = $query->where('css_rit_request_info.request_info_id','LIKE','%'.$searchkey.'%');
        //$query = $query->orwhere('css_rit_request_info.employee_id','LIKE','%'.$searchkey.'%');
        //$query = $query->orwhere('css_rit_request_info.employee_first_nm','LIKE','%'.$searchkey.'%');
        //$query = $query->orwhere('css_rit_request_info.employee_last_nm','LIKE','%'.$searchkey.'%');
        //$query = $query->orwhere('css_rit_req_wrk_sites_info.cur_status','LIKE','%'.$searchkey.'%');
    }
    


    return $getEmpInfo->paginate($pageRows);

}

view.php

@if($ resultArr [ 'pageRow']) @endif 围棋   
                <label>Row</label>
                  @if($resultArr['search'])
                  <input type="hidden" class="form-control" name='search' value= '{{ $resultArr['search'] }}'>
                  @endif
                <select class="form-control" name="pageRow" id='pageRow'>
                  @for($j=0;$j<count($resultArr['pageRowsArr']);$j++)
                      <option value={{ $resultArr['pageRowsArr'][$j] }} {{ $resultArr['pageRowsArr'][$j] == $resultArr['pageRow'] ? 'selected' : '' }}>{{ $resultArr['pageRowsArr'][$j] }}</option>
                  @endfor
                </select>
              
              </div>
              <!-- <button type="submit" class="btn btn-sm btn-primary">Actions</button> -->
            </form>
            </td>
            </tr>
            </table>              
          </div>
         <!--  SEARCH END -->
克雷戈帕尔
 克雷戈帕尔
3个月前(32,700 XP)

@madala你必须调用该->currentPage()方法来AbstractPaginator扩展它LengthAwarePaginator快来看看这里该方法的代码这将返回受保护的$currentPage属性。

 
马达拉
马达拉
3个月前(5,560 XP)

@craigpaul嗨,你能告诉我我必须做什么,因为我是这个框架的新工作。请...

 
克雷戈帕尔
 克雷戈帕尔
3个月前(32,700 XP)

@madala你打电话的地方->currentPage只是用以下代替它->currentPage()

$currentPage = $allEmpPeInfo->currentPage();

// Where $allEmpPeInfo is an instance of LengthAwarePaginator
 

来自 https://laracasts.com/discuss/channels/laravel/cannot-access-protected-property-illuminatepagination...

普通分类: