Welcome Guest, Not a member yet? Register   Sign In
HELP : CodeIgniter 2 + Doctrine 2 Pagination
#1

[eluser]stcoid1[/eluser]
Hi, All..

Help me please, sample pagination CI 2 + Doctrine 2.
I have try, but in our view, pagination not displaying the desired results per page.

models
Code:
<?php

namespace company_group\models;

/**
* @Entity
* @Table(name="company_group")
*/
class Post {

    /**
     * @Id
     * @Column(type="integer")
     * @GeneratedValue
     */
    private $id;

    /**
     * @Column(type="string", length=30, nullable=false)
     */
    private $group_company_code;
  
  /**
     * @Column(type="string", length=100, nullable=false)
     */
    private $group_company_name;
  
    /**
     * @Column(type="text")
     */
    private $address;

/**
     * @Column(type="string", length=10, nullable=false)
     */
    private $post_code;

/**
     * @Column(type="string", length=100, nullable=false)
     */
    private $city;

/**
     * @Column(type="string", length=100, nullable=false)
     */
    private $region;

/**
     * @Column(type="string", length=100, nullable=false)
     */
    private $country;

/**
     * @Column(type="string", length=100, nullable=false)
     */
    private $created_by;

/**
     * @Column(type="datetime")
     */
    private $last_update;

/**
     * @Column(type="string", length=100, nullable=false)
     */
    private $last_update_by;

/**
     * @Column(type="integer", length=1)
     */
    private $row_status;  
  
  
  public function id($value = NULL)
  {
   if (is_null($value))
    return $this->id;
   else
    $this->id = $value;
  }
  
  public function group_company_code($value = NULL)
  {
   if (is_null($value))
    return $this->group_company_code;
   else
    $this->group_company_code = $value;
  }
  
  public function group_company_name($value = NULL)
  {
   if (is_null($value))
    return $this->group_company_name;
   else
    $this->group_company_name = $value;
  }
  
  public function address($value = NULL)
  {
   if (is_null($value))
    return $this->address;
   else
    $this->address = $value;
  }
  
  public function post_code($value = NULL)
  {
   if (is_null($value))
    return $this->post_code;
   else
    $this->post_code = $value;
  }
  
  public function city($value = NULL)
  {
   if (is_null($value))
    return $this->city;
   else
    $this->city = $value;
  }
  
  public function region($value = NULL)
  {
   if (is_null($value))
    return $this->region;
   else
    $this->region = $value;
  }
  
  public function country($value = NULL)
  {
   if (is_null($value))
    return $this->country;
   else
    $this->country = $value;
  }
  
  public function created_by($value = NULL)
  {
   if (is_null($value))
    return $this->created_by;
   else
    $this->created_by = $value;
  }
  
  public function last_update($value = NULL)
  {
   if (is_null($value))
    return $this->last_update;
   else
    $this->last_update = $value;
  }
  
  public function last_update_by($value = NULL)
  {
   if (is_null($value))
    return $this->last_update_by;
   else
    $this->last_update_by = $value;
  }
  
  public function row_status($value = NULL)
  {
   if (is_null($value))
    return $this->row_status;
   else
    $this->row_status = $value;
  }
  
  public function numRecords($id)
  {
     $this->load->helper('url');
   $this->load->library('doctrine');
    
         $result = $this->doctrine->em->create()
             ->select('COUNT(*) as total')
             ->from('company_group')
                ->where("group_company_code LIKE '%$id%'")
             ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
             ->fetchOne();  
         echo $result['total'];
   return $result['total'];  
     }
      
       public function getRecordsArray($id,$offset,$limit) {  
      $this->load->helper('url');
   $this->load->library('doctrine');
         $q = $this->doctrine->em->create()
                ->select('*')
                ->from('company_group')
                ->where("group_company_code LIKE '%$id%'")
                ->limit($limit)
                ->offset($offset)
                ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
             ->execute();          
            return $q;
        }
  
  
}


/* End of file Post.php */
/* Location: ./application/modules/company_group/modules/Post.php */

controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

use company_group\models\Post;

class Posts extends MX_Controller
{
function list_company_group($offset=0)
{
  $where="";
  $this->load->helper('url');
  $this->load->library('doctrine');
  $this->load->library('session');
  
  
$row = $this->doctrine->em->createQuery("select u from company_group\models\Post u".$where)->getResult();
  $num_records=count($row);
  
  $per_page = 10;
        $limit=$per_page;
        

  if ($num_records > $per_page) {
            
             $this->load->library('pagination');
                $config['base_url'] = base_url() . "index.php/company_group/posts/list_company_group".$no_urut."/page";
    $config['total_rows'] = $num_records;
    $config['per_page'] =  $per_page;
    $this->pagination->initialize($config);
        }
  //load view dan array
  $this->load->view('list_company_group', array('row' => $row));
}
}

Thanks
#2

[eluser]stcoid1[/eluser]
Update information...

CI 2 + Doctrine 2 (Paging)

to display the paging has been able,
but to move page to page can not be able.

Please Help Me, Master2
Controller
Code:
function list_company_group($id='')
{
  $this->load->helper('url');
  $this->load->library('doctrine');
  $this->load->library('pagination');
  $this->load->library('session');
  
  
  if (isset($_GET['id']))
  {
   $data['id'] =  $this->input->get('id');
   $this->session->set_userdata('id', $data['id']);
   $no_urut=  $this->input->get('id');
   $data['no_urut']=$this->session->userdata('no_urut'.$this->input->get('id').'');
  }
  else
  {
   $data['id']=$id;
   $no_urut=$id;
   $data['no_urut']=$this->session->userdata('no_urut'.$id.'');
  }
  
  if (isset($_GET['offset']))
  {
   $data['offset'] =  $this->input->post('offset');
   $this->session->set_userdata('offset', $data['offset']);
  }
  else
  {
   $data['offset'] =  0;
   $offset=0;
  }
  
  if (isset($_GET['limit']))
  {
   $data['limit'] =  $this->input->post('limit');
   $this->session->set_userdata('limit', $data['limit']);
   $data['per_page'] =  $this->input->post('per_page');
   $this->session->set_userdata('per_page', $data['per_page']);
  }
  else
  {
   $data['limit'] =  10;
   $limit=10;
   $data['per_page'] =  $limit;
   $per_page=$limit;
  }
  
  $where=" u.group_company_code LIKE '%1%'";
  
  //buat query
  //$row = $this->doctrine->em->createQuery("select u from company_group\models\Post u ".$where)->getResult();
  //$num_records=count($row);
  $calc_row = $this->doctrine->em->createQuery("select u from company_group\models\Post u ")->getResult();
  $num_records=count($calc_row);
  
  $row = $this->doctrine->em->createQuery("select u from company_group\models\Post u ")
          ->setMaxResults($limit)
          ->setFirstResult($offset)
    ->getResult();
  if ($id=="page") { $id=""; }
  if ($num_records > $per_page) {
       //echo $num_records;        
                $config['base_url'] =site_url("company_group/posts/list_company_group".$id."/page");
    $config['total_rows'] = $num_records;
    $config['per_page'] =  $per_page;
    $pagination['per_page']  = $limit;
    $pagination['uri_segment'] = 4;
    $pagination['num_links']  = 4;
    $this->pagination->initialize($config);
    //$row['detail'] = $this->main_model->search_customer($pagination['per_page'],$this->uri->segment(4,0),$data['field'],$data['option_search'],$data['value_kata_kunci'],$data['value1_kata_kunci']);
        }
  //load view dan array
  $this->load->view('list_company_group', array('row' => $row, 'id' => $id, 'no_urut' => $no_urut, 'num_records' => $num_records));
}

Testing URL : http://bkuprojects.us/ci-mysql/index.php...pany_group
#3

[eluser]stcoid1[/eluser]
Problem has been completed

asked and answered himself, wkwkwkwkw

so...

I am used "$this->uri->segment($x)" for get page/10

$x=integer
in my case, $x=5
1 2 3 4 5
http://bkuprojects.us/ci-mysql/index.php...up/page/10

1 = company_group
2 = posts
3 = list_company_group
4 = page
5 = 10

Happy Coding




Theme © iAndrew 2016 - Forum software by © MyBB