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;}我从上面的代码中得到了错误。
Warning: usort() expects parameter 1 to be array, null given in [...]
Warning: array_slice() expects parameter 1 to be array, null given in [...]有人能帮我解决他的问题吗?
发布于 2016-05-26 14:44:41
我认为这$->$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;}}发布于 2019-03-04 18:42:13
我来晚了,但是$ this ->$data应该是$this->data。删除"data“前面的"$”。
https://stackoverflow.com/questions/37453304
复制相似问题