My controller is flex and my function name is post_blog. I have done the routing for this function $config['blog'] = 'flex/post_blog'. Till this everything is working fine. I added pagination for the page which is loaded by above function and my $config['base_url'] = 'blog'. Everything is fine on my first page but on the second page it is showing page not found.
How do I solve this problem?
$this->load->library('pagination');
if($this->uri->segment(2)){
$page = ($this->uri->segment(2)) ;
}
else{
$page = 1;
}
$config = array();
$config['base_url'] = base_url('blog');
$config['total_rows'] = $post_count;
$config['per_page'] = 15;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['cur_tag_open'] = ' <a class="current"><b>';
$config['cur_tag_close'] = '</b></a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$offset=(($page-1)*$config["per_page"]) ;
$this->pagination->initialize($config);
$str_links = $this->pagination->create_links();
$data['links'] = explode(' ',$str_links );
Try
$config['base_url'] = base_url('controller_name/blog');
$config['uri_segment'] = 3;
Also remove echo $page;exit;
Try Changing $config['num_links'] = 2; to $config['num_links'] = $post_count;
Related
Can anyone please help me? I am trying to paginate my table. all links are working, but the items are repeated on other pages. I tried similar questions on here, but nothing is working.
function index($type="deposit", $limit_from=0)
{
$limit_from = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$total_records = $this->Expense->get_total_rows($type);
$data['controller_name'] = $this->get_controller_name();
$lines_per_page = 3;
$data[$type.'s'] = $this->Expense->get_records($lines_per_page, $limit_from, $type);
$config['base_url'] = base_url('index.php/expenses/index/'.$type);
$config['total_rows'] = $total_records;
$config['per_page'] = 3;
$config["uri_segment"] = 4;
// $choice = $total_records / $config['per_page'];
// $config['num_links'] = round($choice);
$config['use_page_numbers'] = TRUE;
$config['first_url'] = base_url('index.php/expenses/index/'.$type.'/1');
$this->pagination->initialize($config);
$data["links"] = $this->pagination->create_links();
$this->load->view('expenses/'.$type, $data);
$this->_remove_duplicate_cookies();
}
Thank you all. I got it to work: below is what I finally did and it is working great!
function index($type="deposit", $sort_by='deposit_date', $sort_order='asc', $page_limit=0)
{
$data['controller_name'] = $this->get_controller_name();
$config = array();
$config['base_url'] = site_url("expenses/index/$type/$sort_by/$sort_order");
$config['total_rows'] = $this->Expense->get_total_rows($type);
$config['per_page'] = 4;
$config["uri_segment"] = 6;
$data['num_rows'] = $config['total_rows'];
$data['type'] = $type;
$this->pagination->initialize($config);
$page = ($this->uri->segment(6)) ? $this->uri->segment(6) : 0;
$data[$type.'s'] = $this->Expense->get_records($config["per_page"], $page, $type, $sort_by, $sort_order);
$data["links"] = $this->pagination->create_links();
$data['headers'] = $this->Expense->table_headers($type);
$data['sort_by'] = $sort_by;
$data['sort_order'] = $sort_order;
$this->load->view('expenses/'.$type, $data);
$this->_remove_duplicate_cookies();
}
In codeigniter Pagination ,I have the pagination links like below.
EG 1 : 1 2 3 > Last ›
EG 2 : ‹ First < 5 6 7 8 9 > Last ›
From the above link how to remove the ">" all arrow mark from the pagination link.
is any keyword set in config parameters.
My code :
public function index()
{
$limit = ($this->uri->segment(4) > 0)?$this->uri->segment(4):0;
$config['base_url'] =base_url().'/dep/index/';
$config["total_rows"] = sizeof($this->MODEL_NAME->COUNT_DEP($companyID, $sortBy, $orderBy));
$config['per_page'] =5;
$config['uri_segment'] = 4;
$config['next_link'] = '';
$config['prev_link'] = '';
$config['num_links'] = 2;
$data["CE"] = $this->MODEL_NAME->get_dep($dep_id, $sortBy, $orderBy,$config["per_page"], $limit);
$data["total_count"] = $config["total_rows"];
$this->pagination->initialize($config);
$data["links"] = $this->pagination->create_links();
$this->load->view('dep/home',$data);
}
You can do with following 4 options:
$config['next_link'] = '';
$config['prev_link'] = '';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
I want your code, but try this
$config['next_link'] = '';
$config['prev_link'] = '';
$config['next_link'] = '<img src="'.base_url().'backend/images/right-arrow.png" >';
$config['prev_link'] = '<img src="'.base_url().'backend/images/left-arrow.png" >';
$config['base_url'] = ''.base_url().'admin/home/userList/?id='.$id.'';
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open']='<li><a href="[removed]void(0);" class="page_active">';
$config['cur_tag_close']='</a></li>';
i am using codeigniter pagination with per page 20 result but it get only two result when i click on pagination mean page number like 2, 3, 4
following is my controller
function restaurant_listing()
{
$config['base_url'] = base_url() . 'admin/restaurant/restaurant_listing/';
//$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
//$config['base_url'] .= preg_replace('#/+$#','',dirname($_SERVER['SCRIPT_NAME'])).'/';
$config['total_rows'] = $this->restaurant_model->record_count();
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$config['num_links'] = 10;
$config['use_page_numbers'] = TRUE;
$config['cur_tag_open'] = '<b>';
$config['cur_tag_close'] = '</b>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data["results"] = $this->restaurant_model->restlisting($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data['content'] = $this->load->view('admin/restaurant_listing', $data, true);
$this->load->view('admin/template', $data);
}
my view file contain
<div class="pagination"> <?php echo $links; ?> </div>
here i am showing pagination
maybe can fix your code i use this code for pagnation
controller code
public restaurant_listing()
{
$restaurant=$this->uri->segment(4);
$limit_ti=20;
if(!$restaurant):
offset_ti = 0;
else:
$offset_ti = $restaurant;
endif;
$this->load->model('Restaurant_model');// call model
$this->load->library('pagination'); // call library
$query=$this->restaurant_model->restlisting($limit_ti,$offset_ti); // geting an article
$total_page = $this->restaurant_model->record_count(); // count row
/** Pagination **/
$config['base_url'] = base_url().'admin/restaurant/restaurant_listing/';
$config['total_rows'] =$total_page->num_rows();
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$config['num_links'] = 10;
$config['use_page_numbers'] = TRUE;
$config['cur_tag_open'] = '<b>';
$config['cur_tag_close'] = '</b>';
$this->pagination->initialize($config);
$data = array('query' => $query,'page'=>$restaurant);
$data['content'] = 'admin/restaurant_listing';
$this->load->view('template', $data);
}
models code
function restlisting($limit,$ofset){
$query=$this->db->query("select * from *name table* order by id ASC LIMIT $ofset,$limit");
return $query;
}
function record_count(){
$query=$this->db->query("select * from *name table*");
return $query;
}
view code
<div class="pagination"><?php echo $this->pagination->create_links(); // call the pagnation?></div>
I want to display some specific data from database through pagination using CI.but pagination by default passess parameter in function which creates problem for me.
Here is my Controller
function page($catagoryid){
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/pagination/page/';
$count = $this->db->query("select * from tbl_products where category_id='$categoryid'");
$total=$count->num_rows();
$per_page = 4;
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->model("mpagination");
$data['list'] = $this->mpagination->get_s(,$categoryid,$config['per_page'],$this->uri->segment(3));
if ($data['list']!== null){
$this->load->view('pagination_view', $data);
}
else {
$this->load->view('noresult');
}
}
Here is my Model
function get_s($categoryid,$num, $offset) {
$this->db->select ('*');
->where('category_id',$categoryid); // field name
$sql = $this->db->get('tbl_products',$num, $offset); // table name
if ($sql->num_rows () >0) {
return $sql->result();
}
else {
return null;
}
}
Here is my view
<?php
foreach($list as $row):?>
<?php echo $row->_prduct_id." ".$row->name." ".$row->description;?>
<br/>
<?php endforeach;?>
<br/>
<?php echo $pagination; ?>
This code work at first but when i clicked on second link of pagination it will not work because by default pagination sends its value to url as parameter and doesnot show data.
what can i do?
I didn't understand your code properly but this is the way you need to do pagination.
public function page($category_id)
{
$result = $this->model_file->model_function($category_id);
$start_index = 0;
$total_rows = count($result);
$items_per_page = 10;
$filtered = array_splice($result,$start_index,$items_per_page);
$model['data'] = $filtered;
$model['page_link'] = create_page_links (base_url()."/controller_file_name/page", $items_per_page, $total_rows);
$this->load->view('view_file_name_path',$model);
}
function create_page_links($base_url, $per_page, $total_rows) {
$CI = & get_instance();
$CI->load->library('pagination');
$config['base_url'] = $base_url;
$config['total_rows'] = $total_rows;
$config['per_page'] = $per_page;
$CI->pagination->initialize($config);
return $CI->pagination->create_links();
}
Try like this
public function index($offset = 0)
{
$language_id = 1;
$this->load->library('pagination');
$limit = 10;
$total = $this->legend_model->get_legend_count($language_id);
$config['base_url'] = base_url().'legend/index/';
$config['total_rows'] = $total;
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['first_link'] = '<< First';
$config['last_link'] = 'Last >>';
$config['next_link'] = 'Next ' . '>';
$config['prev_link'] = '<' . ' Previous';
$config['num_tag_open'] = '<span class="number">';
$config['num_tag_close'] = '</span>';
$config['cur_tag_open'] = '<span class="current"><a href="#">';
$config['cur_tag_close'] = '</a></span>';
$this->pagination->initialize($config);
$data['offset'] = $offset;
$data['legends'] = $this->legend_model->get_legend($language_id, $limit, $offset);
$this->template->write('title', 'Legend : Manage Legend');
$this->template->write_view('content', 'legend/index', $data);
$this->template->render();
}
I set the CodeIgniter pagination's attributes but I am getting an error.
1 2 3 4 5 >
My pagination is working on pages 2-5 except page number 1. I do not realizing why it's happening. Here is my controller function where controller name is c_forum.
function show_posts_by_chapter($id_chapter=false) {
if($id_chapter==false)
show_404();
$config = array();
$config["base_url"] = base_url() . "index.php/c_forum/show_posts_by_chapter/" . $id_chapter.'/';
$config['total_rows'] = $this->m_forum->num_rows_by_chapter($id_chapter);
$config['per_page'] = 2;
$configp['uri_segment'] = 4;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['chapter_id'] = $id_chapter;
$data['allowed'] = $this->_get_level();
$data['count_rows'] = $config['total_rows'];
$data['posts_all'] = $this->m_forum->get_posts_by_chapter($config['per_page'], $page, $id_chapter);
$data['links'] = $this->pagination->create_links();
$this->load->view('forum/show_posts', $data);
}
View is simple :
`<?php echo $links; ?>`
Got answe: I used $configp['uri_segment'] = 4; and it should be $config['uri_segment'] = 4;
$configp['uri_segment'] = 4;
This should be
$config['uri_segment'] = 4;