2016-10-12 6 views
0

私は非常に始めから、私はコードイグナイタで小さなCMSを作成していると私はいくつかの問題に直面します。私はPHPフレームワークを扱う上でジュニアなので、私に怒らないようにしてください。CodeIgniter。許可されたメモリサイズのエラーと改ページ

現在、私はデータベースからの車両モデルリストを持っています。だから私はCodeIgniterのからのエラーを得た:エラー

メッセージ:

A PHPエラーが

重要度発生しました。このとき

の可メモリサイズをIはすでにコメントしていますコードイグナイター出力コンフィギュレーションファイルのコード行。このエラーが表示されます。そして、私は持っている価値の明確なリストを持っています。しかし、あまりにも多く。だから私はページ変更について考えました。

あなたの意見は何ですか、それは私を助けることができますか?たぶん、より良いアドバイス/提案がありますか?

私はそのエラーを無効にしてページネーションを作成しようとしましたが、失敗しました。

は、これは私のコントローラである場合、 "リスト":

 public function lists(){ 

      //get models 
      $data['models'] = $this->Model_model->get_models('id', 'DESC'); 
      //get brands 
      $data['brands'] = $this->Model_model->get_brands('id', 'DESC'); 

      //get brands 
      $data['brand'] = $this->Model_model->get_brands('id', 'DESC'); 
      //get categories 
      $data['categories'] = $this->Model_model->get_categories('id', 'DESC'); 
      //get Users 
      //$data['users'] = $this->User_model->get_users('id', 'DESC', 5);   

      //View 
      $data['main_content'] = 'admin/models/lists'; 
      $this->load->view('admin/layouts/main', $data); 
     } 

これは、モデルファイルからコードです:

<?php 
class Model_model extends CI_Model 
{ 
    /* 
    * Get vehicle models 
    * 
    * @param - $order_by (string) 
    * @param - $sort (string) 
    * @param - $limit (int) 
    * @param - $offset (int) 
    * 
    * */ 

    public function get_models($order_by = null, $sort = 'DESC', $limit = null, $offset = 0) 
    { 
     $this->db->select('vm.*, vb.v_brand_name as v_brand_name, vc.category_name as category_name, u.first_name, u.last_name'); 
     $this->db->from('vehicle_models as vm'); 
     $this->db->join('vehicle_brands as vb', 'vb.id = vm.vehicle_brand_id'); 
     $this->db->join('vehicle_category as vc', 'vc.id = vb.vehicle_category_id', 'vb.vehicle_category_id = vm.vehicle_category_id', 'left'); 
     $this->db->join('users as u', 'u.id = vb.user_id', 'left'); 
     if ($limit != null) { 
      $this->db->limit($limit, $offset); 
     } 
     if ($order_by != null) { 
      $this->db->order_by($order_by, $sort); 
     } 
     $query = $this->db->get(); 
     return $query->result(); 
    }  

    /* 
    * 
    *Get Menu Items 
    * 
    * */ 
    /* public function get_models(){ 
      $this->db->where('id', 1); 
      $this->db->order_by('id'); 
      $query = $this->db->get('vehicle_models'); 
      return $query->result; 
     }*/  

    /* 
    *GET SINGLE ARTICLE 
    * */ 
    public function get_model($id) 
    { 
     $this->db->where('id', $id); 
     $query = $this->db->get('vehicle_models'); 
     return $query->row(); 
    } 

    /* 
     * Get vehicle Categories 
     * 
     * @param - $order_by (string) 
     * @param - $sort (string) 
     * @param - $limit (int) 
     * @param - $offset (int) 
     * 
     * */ 
    public function get_categories($order_by = null, $sort = 'DESC', $limit = null, $offset = 0) 
    { 
     $this->db->select('*'); 
     $this->db->from('vehicle_category'); 
     if ($limit != null) { 
      $this->db->limit($limit, $offset); 
     } 
     if ($order_by != null) { 
      $this->db->order_by($order_by, $sort); 
     } 
     $query = $this->db->get(); 
     return $query->result(); 
    }  

    /* 
* Get vehicle Brands 
* 
* @param - $order_by (string) 
* @param - $sort (string) 
* @param - $limit (int) 
* @param - $offset (int) 
* 
* */ 

    public function get_brands($order_by = null, $sort = 'DESC', $limit = null, $offset = 0) 
    { 
     $this->db->select('*'); 
     $this->db->from('vehicle_brands'); 
     if ($limit != null) { 
      $this->db->limit($limit, $offset); 
     } 
     if ($order_by != null) { 
      $this->db->order_by($order_by, $sort); 
     } 
     $query = $this->db->get(); 
     return $query->result(); 
    } 

    /* 
    * 
    *Insert Model 
    * 
    * */ 

    public function insert($data){ 
     $this->db->insert('vehicle_models', $data); 
     return true; 
    } 

    /*public function insert_models($data){ 
     $models = implode(',',$_POST['v_model_name']); 
     $this->db->insert('vehicle_models', $data); 
     $this->db->into('vehicle_models', $data); 
     $this->db->values($model); 
    }*/ 

    public function update($data, $id){ 
     $this->db->where('id', $id); 
     $this->db->update('vehicle_models', $data); 
     return true; 
    } 

    public function did_delete_row($id){ 
     $this -> db -> where('id', $id); 
     $this -> db -> delete('vehicle_models'); 
     return true; 
    }  

    /* --------------------------- PAGINATION ---------------------------------*/ 

    public function __construct() { 
     parent::__construct(); 
    } 

    public function record_count() { 
     return $this->db->count_all("vehicle_models"); 
    } 

    public function fetch_countries($limit, $start) { 
     $this->db->limit($limit, $start); 
     $query = $this->db->get("vehicle_models"); 

     if ($query->num_rows() > 0) { 
      foreach ($query->result() as $row) { 
       $data[] = $row; 
      } 
      return $data; 
     } 
     return false; 
    } 

    /*--------------------------  AND OF PAGINATION ---------------------------------------*/ 
} 

そして、これが私のビューファイルです:

<?php foreach($categories as $category) :?> 
    <?php 
    $this->load->helper("url");/
    $postid = $this->uri->segment(4); 
    if ($category->id == $postid): 
     ?> 
     <!-- *************************   ****************************************--> 
     <div class="table-responsive col-md-12"> 
      <h2><?php echo $category->category_name; ?></h2> 
      <table class="table table-striped"> 
       <thead> 
       <tr> 
        <th>Model (+View)</th> 
        <th>Brand</th> 
        <th>Category</th> 
        <th></th> 
        <th>Moves</th> 

       </tr> 
       </thead> 
       <tbody> 
       <?php foreach ($models as $model) : ?> 
        <?php if($model->vehicle_category_id == $postid) :?> <!- 
         <tr> 
          <td> 
           <a href="#" id="<?php echo $model->id; ?>"><?php echo $model->v_model_name; ?></a> 
          </td> 
          <?php foreach($brands as $brand) :?><?php if($model->vehicle_brand_id == $brand->id) :?> 
          <td> 
           <a href="<?php echo base_url(); ?>admin/brands/edit/<?php echo $brand->id; ?>" id="<?php echo $brand->id; ?>"><?php echo $brand->v_brand_name; ?></a> 
          </td> 
           <?php endif; ?> 
          <?php endforeach; ?> 
          <td> 
           <a href="#" id="<?php echo $model->vehicle_category_id; ?>"><?php echo $model->category_name; ?></a> 
          </td> 
          <td> 

          </td> 
          <td> 
           <a href="<?php echo base_url(); ?>admin/models/edit/<?php echo $model->id; ?>" class="btn btn-primary">Edit</a> 
           <a href="<?php echo base_url(); ?>admin/models/delete_row/<?php echo $model->id; ?>" class="btn btn-danger">Delete</a> 
          </td> 
         </tr> 
        <?php endif; ?> 
       <?php endforeach; ?> 
       </tbody> 
      </table> 
     </div> 
     <!-- *************************   ****************************************--> 
    <?php endif;?> 
<?php endforeach; ?> 

This how the list looks like

**その他の質問** 誰かがPAGINATIONの作成を手伝うことができますか?

私は、「リスト」コントローラ機能にこのコードを入れてみましたが、そのdidntの 作業:

public function lists1(){ 
$this->load->library('pagination'); 
$config['base_url'] = 'http://localhost/test/admin/Models/lists/'; 
$config['per_page'] = 5; 
$config['num_links'] = 5; 
$config['total_rows'] = $this->db->get('vehicle_models')->num_rows(); 
    /*$config['total_rows'] = $this->db->get_models('v_model_name');*/ 

$this->pagination->initialize($config); 
$data['query'] = $this->db->get('vehicle_models', $config['per_page'],$this->uri->segment(4)); /*segment*/ 
$this->load->view('admin/models/lists', $data); /*nuoroda*/ 

echo $this->pagination->create_links(); 
     $data['main_content'] = 'admin/models/lists'; 
     $this->load->view('admin/layouts/main', $data); 

ウィルのページネーションは私が多くのリストアイテムに対処するのに役立ちますか? 誰かがコードを教えてくれますか?ありがとう。

答えて

0

あなたのcodeigniterコードは、リスト全体を最初に配列に格納しています。その後、画面を構築しようとしています。おそらくSQL結合から始めて、その結合の制限を使用して行数を制限することができます。また、ページ番号のスクリプトページ番号を送信してください。

<?php 

$current = $_GET['page']; 
$rowCount = $_GET['length']; 

$sql = "select * from model m 
inner join brand b 
on m.vehicle_brand_id = b.id 
limit ".($current - 1)*($rowCount).",".$rowCount; 

$query = $this->db->query($sql); 
    $content['tableList'] = $query->result(); 

このようにして、データ全体を取得することはありません。その結果、最終的にメモリの枯渇エラーが発生します。

関連する問題