2016-05-26 6 views
0
function prepare_items() { 
    $columns = $this->get_columns(); 
    $hidden = array(); 
    $sortable = $this->get_sortable_columns(); 
    $this->_column_headers = array($columns, $hidden, $sortable); 
    usort($this->$data, array(&$this, 'usort_reorder')); 
    $per_page = 5; 
    $current_page = $this->get_pagenum(); 
    $total_items = count($this->data); 
    $this->found_data = array_slice($this->data,(($current_page-1)* $per_page), $per_page); 
    $this->set_pagination_args(array(
    'total_items' => $total_items, 
    'per_page' => $per_page 
)); 
    $this->items = $this->found_data;} 

上記のコードからエラーが発生します。PHPの警告:usort()は、配列1にパラメータ1があり、array_slice()でnullが指定されていると仮定します。

Warning: usort() expects parameter 1 to be array, null given in [...] 

Warning: array_slice() expects parameter 1 to be array, null given in [...] 

誰でも自分の問題を解決するのに役立つことができますか?

+0

を進める '$このですか? – Thamilan

+0

私は$ this - > $ dataが空を返すと思います – Karthikeyani

答えて

0

だと思います。$ this - > $ dataが空です。この$を確認してください - > $ data`配列 - 配列を返し、値をチェック> $データ(if(!empty($this->$data))と機能

function prepare_items() { 
    $columns = $this->get_columns(); 
    $hidden = array(); 
    $sortable = $this->get_sortable_columns(); 
    $this->_column_headers = array($columns, $hidden, $sortable); 
if(!empty($this->$data) { 
    usort($this->$data, array(&$this, 'usort_reorder')); 
    $per_page = 5; 
    $current_page = $this->get_pagenum(); 
    $total_items = count($this->data); 
    $this->found_data = array_slice($this->data,(($current_page-1)* $per_page), $per_page); 
    $this->set_pagination_args(array(
    'total_items' => $total_items, 
    'per_page' => $per_page 
)); 
    $this->items = $this->found_data;}} 
関連する問題