2

モデル:

class Pagination_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function total_rows() {
    return $this->db->count_all('recipe');
    }
}

コントローラ:

 function browse()
    {
    $this->load->library('pagination');
    $this->load->library('table');

        $config['base_url'] = 'http://localhost/Finals/index.php/login/browse';
        $config['total_rows'] = $this->pagination_model->total_rows();
        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['uri_segment'] = 3;


        $this->pagination->initialize($config);

        $data['records'] = $this->db->get('recipe', $config['per_page'], $this->uri->segment(3));
        //echo "<pre>";print_r( $data['records'] );die;
        $this->load->view('browse' , $data);
    }

私の見解:

 <html>
    <head>
    <title>blablabla</title>
    <link href="../../css/default.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div id="header">
        <div id="logo">
           <h1><a href="#">grr</a></h1>
           <h2>by chief</h2>
        </div>
        <div id="menu">
           <ul>
               <li class="first"><a href="#">Home</a></li>
               <li><a href="#">My Profile</a></li>
               <li><a href="#">My Recipes</a></li>
               <li><a href="#">Browse Recipes</a></li>
               <li><a href="#">Forum</a></li>
           </ul>
        </div>
    </div>
    <div id="content">
        <div id="colOne">
           <div class="post">
              <div class="story">
             <h2>Results:</h2>
                <?php $this->table->generate($records); ?>
                <?php $this->pagination->create_links(); ?>
             </div>
              </div>
           </div>
        </div>
        <div id="footer">
           <p>Copyright &copy; </p>
        </div>
    </body>
    </html>

これは print_r から返されるものです

 [result_id] => mysqli_result Object
            (
                [current_field] => 0
                [field_count] => 8
                [lengths] => 
                [num_rows] => 1
                [type] => 0
            )

        [result_array] => Array
            (
            )

        [result_object] => Array
            (
            )

        [custom_result_object] => Array
            (
            )

        [current_row] => 0
        [num_rows] => 1
        [row_data] => 

私の1ページあたりの制限のため、おそらく1行が表示されます。しかし、なぜ row_data が空なのですか? 行の値を出力する必要がありますか?

さらに、row_data が空だったとしても、pagination create_links() を入力すると、少なくとも正しく表示されるはずですか? ライブラリの読み込みに問題はありますか?

4

2 に答える 2

0

これを変更してください。すべてのレコードを選択し、コントローラー部分で行数を見つけるために合計を記述する悪い方法です。代わりに、モデルで行う必要があります。:

$config['total_rows'] = $this->db->get('recipe')->num_rows();

に:

$config['total_rows'] = $this->model_name->total_rows();
/*Model Function*/
function total_rows(){
    return $this->db->count_all('table_name'); #will return the no. of rows in integer    
}

ページネーションに必要な構成がありません:

$config['uri_segment'] = 3;

CSS、JS ファイルは常に絶対パスで定義します。

<link href="<?=base_url()?>css/default.css" rel="stylesheet" type="text/css">

print_r値を正しく取得していることを確認するために、コントローラーの最後の結果:

$data['records'] = $this->db->get('recipe', $config['per_page'], $this->uri->segment(3) );
echo "<pre>";print_r( $data['records'] );die;
于 2013-10-08T08:04:15.190 に答える
0

Table::generate は文字列を作成します。エコーする必要があります。

            <?php echo $this->table->generate($records); ?>
于 2013-10-08T09:02:14.483 に答える