2016-05-26 1 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;} 

Je reçois cette erreur du code ci-dessus.PHP Attention: usort() s'attend à ce que le paramètre 1 soit array, nul donné dans & array_slice() attend le paramètre 1 à array, null donné en

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

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

Quelqu'un peut-il m'aider à résoudre ses problèmes?

+0

est '$ this -> $ data' un tableau? – Thamilan

+0

Je pense que $ this -> $ data retourne vide – Karthikeyani

Répondre

0

Je pense $ this -> $ data retourne vide. Assurez-vous $ this -> données tableau $ de retour et vérifier la valeur (if(!empty($this->$data)) et procéder à la fonction

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;}}