CodeIgniter 函数不显示?

CodeIgniter function not show?

helper.website.php

public function load_top_players() { 
    $this->load->lib(array('rank_db', 'db'), array(HOST, USER, PASS,CHARACTERS));
    $query = $this->rank_db->query('SELECT name, access FROM users ORDER BY access DESC LIMIT 5');
    while($row = $query->fetch()) {
        $this->rank[] = array(
            'name'  => htmlspecialchars($row['name']),
            'level' => (int)$row['access']
        );
    }
    return $this->rank;
}

view.header.php

<?php
$rank = load::get('website');
$i = 1;
foreach ($rank as $pos => $player) {
    $first = (in_array($i, array(1))) ? '' : '';
    $second = (in_array($i, array(2))) ? '' : '';
    echo '<tr style="'.$first.' '.$second.' '.$third.'">
        <td  >'.$i.'</td>
        <td>'.$player['name'].'</td>
        <td>'.$player['access'].'</td>
    </tr>';
    $i++;
}
?>

它显​​示一个空白页面,没有错误,没有任何错误!

它显​​示的是空白页,因为您没有将任何数据传递到您的视图文件。为了在你的视图文件中获取数据,你必须从你的控制器加载一个包含一些数据的视图。语法是-

<?php

class Your_Controller_Class extends CI_Controller {

   function your_function()
   {
      $data['data'] = 'Your data'; //get it from your model or whatever
      $this->load->view('your_view_file', $data);
   }

}
?>

然后从您的视图文件访问它。

helper.website.php

public function getOnlineCount(){
        $this->load->lib(array('rank_db', 'db'), array(HOST, USER, PASS, CHARACTERS));  
        return $this->registry->rank_db->snumrows('SELECT count(name) as count from users where status <> -1 AND sub_status>= 1');
    }

并在 view.header.php <?php echo load::get('website')->getOnlineCount() ; ?> 中完美运行!我如何将其转换为我的查询