[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