Insert #anchor in final URL with codeigniter pagination - codeigniter

I have one problem with my pagination in codeigniter.
My pagination is in one #section and when I change the pagination the page reload in header, I need add #anchor in final URL.
In this moment my url is:
http://localhost/php_focas/index.php?per_page=3
And I need this:
http://localhost/php_focas/index.php?per_page=3#agenda
Its my controller :
$urlPaginacao = site_url();
//PAGINAÇÃO *****
$get_total_results = $this->admin_model->mostrarAgenda();
$totalResultados = $get_total_results['total'];
$getPaginacao = $this->paginacao($urlPaginacao,$totalResultados, 3);
$getEventos = $this->admin_model->mostrarAgenda($getPaginacao['inicio'], $getPaginacao['quantidadeResultados']);
$data['district'] = $this->admin_model->mostrarDistrict();
$data['local'] = $this->admin_model->mostrarLocal();
$data['life'] = $this->admin_model->mostrarLife();
$data['useful'] = $this->admin_model->mostrarUseful();
$data['agenda'] = $getEventos['dadosGerais']; //dados gerais do model
$data['pag'] = $getPaginacao['paginacao'];
$this->load->view('index', $data);
}
public function paginacao($urlPaginacao, $totalResultados, $resultadosPorPagina = 3){
$config['base_url'] = $urlPaginacao;
$config['total_rows'] = $totalResultados;
$config['per_page'] = $resultadosPorPagina;
$config['page_query_string'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination pagination-sm'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='active disable'><a>";
$config['cur_tag_close'] = "</a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$config['first_link'] = TRUE;
$config['last_link'] = TRUE;
$quantidade = $resultadosPorPagina;
$this->pagination->initialize($config);
$data['quantidadeResultados'] = $quantidade;
$data['inicio'] = $this->input->get('per_page') != NULL ? $this->input->get('per_page') : '0';
$data['paginacao'] = $this->pagination->create_links();
return $data;
}
And it is my model:
public function mostrarAgenda($inicio=NULL, $quantidade=NULL){
$inicio = $inicio != NULL ? "LIMIT {$inicio},{$quantidade}" : "";
$sqlGeral = "SELECT * FROM tblagenda {$inicio}";
$queryGeral = $this->db->query($sqlGeral);
$data['inicio'] = $inicio;
$data['total'] = $queryGeral->num_rows();
$data['dadosGerais'] = $queryGeral->result();
return $data;
}

The solution was adding the following code in my controller inside function pagination() :
$config['suffix'] = '#agenda';
Hope this will help someone in the future.

Related

Getting the same data on pagination in Codeigniter

I am getting the same data when I am clicking on the next button of pagination in CodeIgniter with the following code
public function view($slug){
$data['title']= $slug;
$data['description']= "None";
$postdatacount = $this->Constant_model->snippettagscount($slug);
$checktags= $this->Constant_model->gettags($slug);
if($checktags>0){
if ($postdatacount>0) {
$config = array();
$config["base_url"] = base_url() ."tags/".$slug;
$config["total_rows"] = $postdatacount;
$config["per_page"] = 6;
$config["uri_segment"] = 2;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["links"] = $this->pagination->create_links();
$data["title"] = "All Tags";
$data["description"] = "All Tags";
$data['snippets_tags'] = $this->Constant_model->get_tags($config["per_page"],$page,$slug);
$this->snippetfunctions->add_count('tags','tag_name',$slug);
$this->load->view('view_tag_snippets', $data);
}else {
$data["title"] = "No Snippet Found for this Tag";
$data["description"] = "No Snippet Found for this Tag";
$data["slug"] =$slug;
$this->load->view('error_tags',$data);
}
}else{
$this->load->view('404',$data);
}
}
Primary URL Made on this function is
http://127.0.0.1/Mytredin_codesup/tags/user-interface
When I am clicking on Next button following URL is made but not loading the next data but loading the same data and the same thing happens on every next page.
http://127.0.0.1/Mytredin_codesup/tags/user-interface/1
Routes I am using is
$route['tags/(:any)/(:num)'] = 'tags/view/$1/$2';
$route['tags/(:any)'] = 'tags/view/$1';
The problem is with the config $config["uri_segment"] = 2;, according to your routing the page variable is at segment 3.
Use $config["uri_segment"] = 3; instead of $config["uri_segment"] = 2;. Also change the line $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
More details read

pagination doesn't work in codeigniter

I made an optional search that makes the user search with username or customer or date from/to the result returning well to the first page but if I click on another page the result return nothing
this my front and all that input optional
i think the problem the pagination path because if i fill all inputs the pagination path become
controllername/userid/customerid/fromdate/todate
and if skip any input I find the pagination path is missing that
this my controller
public function search($page_num = 1){
$this->load->library('pagination');
$this->load->helper("url");
$this->load->model(array('CustomReport_m','user','Customer_m')); // This array to save number of lines only
$username=$this->input->post('select_user');
$username = ($this->uri->segment(3)) ? $this->uri->segment(3) : $username;
$customer=$this->input->post('select_customer');
$customer = ($this->uri->segment(4)) ? $this->uri->segment(4) : $customer;
$datefrom=$this->input->post('from');
$datefrom = ($this->uri->segment(5)) ? $this->uri->segment(5) : $datefrom;
$dateend=$this->input->post('to');
$dateend = ($this->uri->segment(6)) ? $this->uri->segment(6) : $dateend;
$total_row = $this->CustomReport_m->search_count($username,$customer,$datefrom,$dateend);
//$config['use_page_numbers'] = TRUE;
$config['base_url'] = site_url("CustomReport/search/$username/$customer/$datefrom/$dateend");
$config['total_rows'] = $total_row;
$config['per_page'] = 10;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = floor($choice);
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
if ($this->uri->segment(7)) {
$page = ($this->uri->segment(7));
} else {
$page = 1;
}
$str_links = $this->pagination->create_links();
$data["links"]= explode(' ', $str_links);
$data['users']=$this->user->display_users();
$data['userdata'] = $this->user->userdata();
$data['customers']= $this->Customer_m->index();
// if(isset($_POST['submit'])){
$data["rsl"] =$this->CustomReport_m->search($username,$customer,$datefrom,$dateend,$config["per_page"],$page);
$this->load->view('customreport_v',$data);
// }else{
// redirect('CustomReport','refresh');
// }
}
This is my model
public function search_count($username,$customer,$datefrom,$dateend) {
$this->db->select('*');
$this->db->from('transactions');
if (!empty($customer)){
$this->db->where('t_customer_id',$customer);
}
if (!empty($username)){
$this->db->where('t_u_id',$username);
}
if (!empty($dateend)){
$this->db->where('t_date <=',$dateend);
}
if (!empty($datefrom)){
$this->db->where('t_date >=',$datefrom);
}
return $this->db->get()->num_rows();
}
public function search($username,$customer,$datefrom,$dateend,$limit,$start)
{
$start=$start-1;
$this->db->select('*');
$this->db->from('transactions');
if (!empty($customer)){
$this->db->where('t_customer_id',$customer);
}
if (!empty($username)){
$this->db->where('t_u_id',$username);
}
if (!empty($dateend)){
$this->db->where('t_date <=',$dateend);
}
if (!empty($datefrom)){
$this->db->where('t_date >=',$datefrom);
}
$this->db->limit($limit,$start);
$query=$this->db->get();
if($query->num_rows() > 0){
return $query->result();
}else{
return $query->result();
}
}
this my route
$route['CustomReport/(:num)']="CustomReport/index/$1";

Codeigniter: When i do search the pagination page still remains

I have a problem when i do search the pagination number still remains in the url result to showing no resuts. for example when i click a pagination link my url looks like this example/index.php/example/info/10 then when i do search, the url now the url looks like this example/index.php/example/info/10?search=word
How can i fixed this problem
Controller
public function info($offset=0)
{
$this->load->library('pagination');
$search = $this->input->get('search');
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
if($this->input->get('search')){
$count = $this->ticketing_mdl->count_all_ticket();
$config['total_rows'] = $count;
$config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['base_url'] = "/ticketing/index.php/ticketing/info";
$config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
}else{
$this->db->where('is_valid','1');
$config['total_rows'] = $this->db->count_all_results('db_ticketing.tr_ticket');
$config['base_url'] = "/ticketing/index.php/ticketing/info";
}
$limit = 10;
$config['per_page'] = $limit;
$config['num_links'] = $limit;
$config['full_tag_open'] = '<div><ul class="pagination pagination-centered">';
$config['full_tag_close'] = '</ul></div>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$config['first_link'] = 'First';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['ticket_list'] = $this->ticketing_mdl->get_all_ticket($limit,$page, $offset);
$this->load->view('ticketing/header');
$this->load->view('ticketing/left_menu');
$this->load->view('ticketing/info',$data);
}
Let me know if i am right.
I think you can control it by defining routes.
Set your $config['base_url'] of pagination library like example/index.php/search and define routes (application/config/routes.php) like
$route['search'] = "example/info";
$route['search/(:num)'] = "example/info/$1";
comment this $config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
And dont forget to set the html form action="echo site_url('search');" method="get"
I hope this will give you some help.

Codeigniter wrong pagination link

I'm creating a pagination using codeigniter.
I want the link to be: site_name/categorie_name/page/id => id is dynamic.
When i create the pagination and when i'm on the page site_name/categorie_name/page/1. the next page link is replaced by site_name/categorie_name/page/1/id.
what should i do?
public function Pagginations($total_row,$baseurl,$per_page) {
$config = array();
$config["base_url"] = $baseurl;
$config["total_rows"] = $total_row;
$config["per_page"] = $per_page;
$config['use_page_numbers'] = TRUE;
//$config['num_links'] = 100;
$config['uri_segment'] = 2 ;
$config['num_links'] = 100;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
if ($this->uri->segment(2)) {
$config['page']= $page = ($this->uri->segment(2));
} else {
$config['page']= $page = 1;
}
$config["links"]=explode(' ', $this->pagination->create_links());
return $config;
}
18 is display of product on one row
$config = $this->Pagginations($total_row,$baseurl,18);

Dynamic title page category - Codeigninter

I'm trying to work on a website and would like to know
how to display the category name in the page title, favicon next to the page?
Example: Mysite - Category 1, Mysite - Category 2
Hello everyone, I'm trying to work on a website and would like to know
how to display the category name in the page title, favicon next to the page?
function cat() {
$offset = (int) $this->uri->segment(4);
$appcat_nome = xss_clean($this->uri->segment(3));
$categoria = $this->appcat->get(array('appcat_url' => $appcat_nome, 'appcat_status' => 1, ));
$this->data['titulo'] = 'Digital Feed';
$cond = array('app_on' => 1);
$this->data['apps2'] = $this->apps->getAll($cond, '', 1000, '', 'app_view DESC');
// Configurações do site.
$this->data['config_site'] = $this->config_site->getAll(array('conCod' => 1))->row();
if (count($categoria) == 1)
{
$where = array('A.appcat_id' => $categoria[0]['appcat_id']);
$total_rows = $this->apps->getAll($where)->num_rows();
$this->data['apps'] = $this->apps->getAll($where, $offset, $this->limit, '');
$this->load->library('pagination');
$config['base_url'] = base_url() . 'apps/cat/'. $appcat_nome . '/';
$config['total_rows'] = $total_rows;
$config['per_page'] = $this->limit;
$config['uri_segment'] = 4;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->data['total_rows'] = $total_rows;
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$this->load->view('site/apps/index', $this->data);
}else{
redirect(base_url().'apps');
}
}
To set title to pages, pass title from controller.
$data["page_title"] = "Category 1";
In view file:
<?php
$title = "Mysite";
if(!empty($page_title))
$title .= " - ".$page_title;
?>
<title><?php echo $title;?></title>

Resources