hi everyone i am trying to build a pagination function in a web project i fallowed the user guide on codeigniter and a tutorial on net tuts here is the link http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-day-7-pagination/
but i keep getting these tow errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$pagination
Filename: views/result_view.php
Line Number: 41
and
Fatal error: Call to a member function create_links() on a non-object in C
cant figure these errors out where are they coming from and how can i fix them can some one help me here is my cmv :
controller
<?php
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->view('result_view', $data);
}
function pagination()
{
$this->load->library('pagination');
$config['base_url'] = 'result_controller/pagination';
$config['total_rows'] = $this->db->get('data')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
$this->load->view('result_view', $data);
}
view
<table border="1">
<tr>
<th>Name</th>
<th>Second Name</th>
<th>Phone</th>
<th>Email</th>
<th>Answer</th>
<th>Comment</th>
</tr>
<?php foreach ($query as $row): ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->second_name; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
<td> <?php echo $row->answerA;?>
<?php echo $row->answerB;?>
<?php echo $row->answerC;?></td>
<td><?php echo $row->comment;?><br></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->pagination->create_links(); ?>
model
<?php
class Result_model extends CI_Model{
function result_getall(){
return $this->db->select('*')
->from('tblanswers, credentials')
->get()
->result_object();
}
}
?>
Remove this line from your view
<?php echo $this->pagination->create_links(); ?>
And paste this one
<?php echo $pagination ?>
EDIT
Instead of having a pagination function put the pagination code inside your getall() function like this:
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->library('pagination');
$config['base_url'] = 'result_controller/getall';
$config['total_rows'] = $this->db->get('data')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
$this->load->view('result_view', $data);
}
}
Related
I've look through lots of question asked about Pagination but I can't really understand how Pagination works. I need Pagination to work on index() and when user enter date range searchdate().In my Controller:
public function __construct() {
parent::__construct();
$this->load->model('ReportModel');
}
public function index()
{
$orders=new ReportModel;
$data['data']=$orders->get_orders();
$this->load->view('includes/header');
$this->load->view('Report/view',$data);
$this->load->view('includes/footer');
}
public function searchDate()
{
$orders=new ReportModel;
$searchfrom = $this->input->post('searchDateFrom');
$searchto = $this->input->post('searchDateTo');
$data['data']=$orders->get_orders($searchfrom,$searchto);
$this->load->view('includes/header');
$this->load->view('Report/view',$data);
$this->load->view('includes/footer');
}
In my Model:
public function get_orders(){
$searchDateFrom = $this->input->post("searchDateFrom");
$searchDateTo = $this->input->post("searchDateTo");
$this->db->select('platform,id,no,date,printed_date');
$this->db->from('orders');
if(!empty($searchDateFrom) || !empty($searchDateTo) || !empty($searchPlatform)){
if (!empty($searchDateFrom)) {
$this->db->where('date >= ', $this->input->post("searchDateFrom"));
}
if (!empty($searchDateTo)) {
$this->db->where('date <= ', $this->input->post("searchDateTo")." 23:59:59");
}
}
$this->db->order_by("date", "desc");
$this->db->limit(300);
$query = $this->db->get();
return $query->result();
}
In my View:
<div class="pull-right">
<form class="form-inline" role="search" action="<?php echo base_url('estoreReport/searchDate')?>" method = "post">
<div class="form-group">
<input type="date" class="form-control" placeholder="Order Date From" name = "searchDateFrom" ">
<input type="date" class="form-control" placeholder="Order Date To" name = "searchDateTo" ">
</div>
<button class="btn btn-default " type="submit" value = "searchDateTo"><i class="glyphicon glyphicon-search"></i>
</form>
</div>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Platform</th>
<th>ID</th>
<th>No</th>
<th>Date</th>
<th>Printed Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $d) { ?>
<tr>
<td ><?php echo $d->platform; ?></td>
<td><?php echo $d->id; ?></td>
<td><?php echo $d->no; ?></td>
<td><?php echo $d->date; ?></td>
<td><?php echo $d->printed_date; ?></td>
<td></td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
I've read CodeIgniter documentation, and know that I should put the configurations in the controller.
public function pagination($count){
$this->load->library('pagination');
$config['base_url'] = base_url('/order/Report/');
$config['total_rows'] = $count;
$config['per_page'] = 100;
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = ;
$config['use_page_numbers'] = TRUE;
$config['reuse_query_string'] = TRUE;
$page = ($this->uri->segment($config["uri_segment"] )) ? $this->uri->segment($config["uri_segment"] ) : 0;
$this->pagination->initialize($config);
$pagination = $this->pagination->create_links();
return array($page, $config['per_page'], $pagination);
}
But I'm still not sure how to do modify other parts of my controller, model and view. I'm a new CodeIgniter learner here, this is my testing page only, please help, thank you.
Your controller should look like this:
public function __construct() {
parent::__construct();
$this->load->model('ReportModel', 'orders');
$this->load->library('pagination');
}
public function index($offset = 0)
{
$data['data']=$this->orders->get_orders($search = array(), $offset);
$config['total_rows'] = $data['total_rows'] = $this->orders->get_orders($search = array(), $offset, true);
$config['base_url'] = base_url('/order/index/');
$config['per_page'] = 100;
$config["uri_segment"] = 3;
$config['reuse_query_string'] = TRUE;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('includes/header');
$this->load->view('Report/view',$data);
$this->load->view('includes/footer');
}
Then your model should be changed to also be able to paginate your results:
public function get_orders($search = array(), $offset = 0, $count = false){
$searchDateFrom = $search["searchDateFrom"];
$searchDateTo = $search["searchDateTo"];
$this->db->select('platform,id,no,date,printed_date');
$this->db->from('orders');
if(!empty($searchDateFrom) || !empty($searchDateTo) || !empty($searchPlatform)){
if (!empty($searchDateFrom)) {
$this->db->where('date >= ', $this->input->post("searchDateFrom"));
}
if (!empty($searchDateTo)) {
$this->db->where('date <= ', $this->input->post("searchDateTo")." 23:59:59");
}
}
$this->db->order_by("date", "desc");
if ( !$count ) {
$this->db->limit(100, $offset);
$query = $this->db->get();
return $query->result();
}
$query = $this->db->get();
return $query->num_rows();
}
Check these:
codeigniter pagination
codeigniter pagination 2
I have given answers to the question for pagination in Codeigniter on StackOverflow. These links have the full description. Hopefully it will help
i am searching for 2 days now but still no luck. my problem with my CodeIgniter Pagination is i have set my controller to show 1 data per page i have 2 data which means i have the 1,2 pagination. the [1] page is currently showing the correct data, but when i try to click [2] it still shows the data from the [1] page plus the url is page=1.
here is my Controller
class Campaign extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('campaign_model');
$this->load->database();
$this->load->library('pagination');
}
function index() {
$this->load->view('campaign_view');
}
function submit() {
$this->form_validation->set_rules('campaignName', 'Campaign Name', 'trim|required|is_unique[ch_campaigns.c_campaign_name]');
if($this->form_validation->run() == FALSE) {
echo validation_errors();
} else {
$campaignName = $this->input->post('campaignName');
$data = array (
'c_campaign_name' => $campaignName
);
$this->db->insert('ch_campaigns', $data);
echo "YES";
}
}
public function campaigns() {
$data = array();
//pagination settings
$config['base_url'] = site_url('campaigns');
$config['total_rows'] = $this->db->count_all('ch_campaigns');
$config['per_page'] = "1";
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$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'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$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);
$data['page'] = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
//call the model function to get the department data
$data['campaignlist'] = $this->campaign_model->get_campaign_list($config["per_page"], $data['page']);
//$data['campaignInfo'] = $this->campaign_model->get_campaign_list();
$data['pagination'] = $this->pagination->create_links();
//load the department_view
//print var_export($data, true);
$this->load->view('campaign_view',$data);
}
}
here is my Model
public function __construct() {
parent::__construct();
}
public function get_campaign_list($limit, $start) {
$this->db->select('*');
$this->db->from('ch_campaigns');
$this->db->limit($limit, $start);
$query = $this->db->get();
if($query->num_rows() > 0 ) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
lastly my Views
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Campaign Name</th>
<th>Owner</th>
<th>Status</th>
<th>Start Date</th>
<th>End Date</th>
<th>Total Leads</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php foreach($campaignlist as $list) { ?>
<tr>
<td><?php echo $list->c_campaign_name; ?></td>
<td><?php echo $list->c_customer_name; ?></td>
<td><?php echo $list->c_status; ?></td>
<td><?php echo $list->c_start_date; ?></td>
<td><?php echo $list->c_end_date; ?></td>
<td></td>
<td><span class="fa fa-caret-square-o-down"></span>
<ul class="dropdown-menu">
<li>Edit</li>
<li>Delete</li>
</ul>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="main-container-footer text-center">
<?php echo $pagination; ?>
</div>
I'm developing this pagination page with ajax on code igniter hmvc but I get this javascript:void(0) on the uri of my link to the next pages. how can I fix this?
here is my codes.
controllers
<?php
class Job_Titles extends MY_Controller{
public function __construct(){
parent::__construct();
$this->load->model('Job_Titles_Model');
$this->load->library('Ajax_pagination');
$this->perPage = 10;
}
// VIEW REDIRECTING /////////////////////////////////////////////////////////
public function index(){
/// view ajax config/////
$data = array();
//total row count
$totalRec = count($this->Job_Titles_Model->getRows());
//configuration
$config['first_link'] = 'First';
$config['div'] = 'postList'; //parent div tag id
$config['base_url'] = base_url().'Job_Titles/ajaxPaginationData';
$config['total_rows'] = $totalRec;
$config['per_page'] = $this->perPage;
$this->ajax_pagination->initialize($config);
$data['content_view'] = 'Job_Titles/jobtitles_read';
$data['content'] = $this->Job_Titles_Model->getRows(array('limit'=>$this->perPage));
$data['false'] = FALSE;
$this->templates->admin_template($data);
}
//// pagination
public function ajaxPaginationData(){
$data = array();
$page = $this->input->post('page');
if(!$page){
$offset = 0;
}else{
$offset = $page;
}
//total row count
$totalRec = count($this->Job_Titles_Model->getRows());
//pagination config
$config['first_link'] = 'First';
$config['base_url'] = base_url().'Job_Titles/ajaxPaginationData';
$config['total_rows'] = $totalRec;
$config['per_page'] = $this->perPage;
$this->ajax_pagination->initialize($config);
//get post data
$data['content_view'] = 'Job_Titles/ajax-pagination-data';
$data['content'] = $this->Job_Titles_Model->getRows(array('start'=>$offset,'limit'=>$this->perPage));
$this->templates->admin_template($data);
}
}
models
public function getRows($params = array()){
$this->db->select('*');
$this->db->from($this->table);
if(array_key_exists("start", $params) && array_key_exists("limit", $params)){
$this->db->limit($params['limit'],$params['start']);
}elseif (!array_key_exists("start", $params) && array_key_exists("limit", $params)) {
$this->db->limit($params['limit']);
}
$query = $this->db->get();
return ($query->num_rows() > 0)?$query->result_array():FALSE;
}
views
<?php
echo anchor('Job_Titles/add_view','ADD ');
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div id = "container" class = "page-header">
<table class= "table table-bordered">
<thead>
<tr>
<th>JOB CODE</th>
<th>JOB NAME</th>
<th></th>
<th></th>
<tr>
</thead>
<tbody>
<?php if(!empty($content)){foreach ($content as $job_title) {?>
<tr>
<td><?php echo $job_title['JOB_CODE']; ?></td>
<td><?php echo $job_title['JOB_NAME']; ?></td>
<td></i></td>
<td><i class="fa fa-trash-o"></i></td>
</tr>
<?php }}else{ ?>
<li class="err_msg">Post(s) not available.</li>
<?php } ?>
</tbody>
</table>
<?php echo $this->ajax_pagination->create_links(); ?>
</div>
I'm developing this pagination page with ajax on code igniter hmvc but I get this javascript:void(0) on the uri of my link to the next pages. how can I fix this?
I am trying to use pagination with codeigniter 3 and bootstrap twitter. When i click the link pagination it's always give me 404 not found.
I think it's my fault for not fully understanding codeigniter URI that's why i need help in my code
Here is my model :
class Mcrud extends CI_Model {
public function record_count() {
return $this->db->count_all("crud");
}
function view() {
$ambil = $this->db->from('crud')->order_by('idcrud', 'DESC')->limit(5, 3)->get();
if ($ambil->num_rows() > 0) {
foreach ($ambil->result() as $data) {
$hasil[] = $data;
}
$ambil->free_result();
return $hasil;
}
}
here is my controller :
class Chome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Mcrud');
}
function index() {
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['nama'] = $session_data['fullname'];
$data['username'] = $session_data['username'];
$data['id'] = $session_data['idlogin'];
$this->load->view('Header', $data);
$this->suratkeluar();
} else {
redirect('welcome', 'refresh');
}
}
function suratkeluar()
{
$result_per_page = 2; // the number of result per page
$config['base_url'] = base_url() . '/Chome/index';
$config['total_rows'] = $this->Mcrud->record_count();
$config['per_page'] = $result_per_page;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$data['data_get'] = $this->Mcrud->view();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('Vhome', $data);
$this->load->view('Footer');
}
and this is my Vhome view :
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<caption>List Data</caption>
<thead>
<tr>
<th width="80px">ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Address</th>
<th width="80px">Action</th>
</tr>
</thead>
<tbody>
<?php
if ($data_get == NULL) {
?>
<div class="alert alert-info" role="alert">Data masih kosong, tolong di isi!</div>
<?php
} else {
foreach ($data_get as $row) {
?>
<tr>
<td><?php echo $row->idcrud; ?></td>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->age; ?></td>
<td><?php echo $row->address; ?></td>
<td>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</td>
<?php
}
}
?>
</tr>
</tbody>
</table>
<?php echo $pagination; ?>
</div>
and last this is my base url in config.php :
$config['base_url'] = 'http://localhost/arsip/';
try to amend this section:
Model:
function view($opset) {
$ambil = $this->db->from('crud')->order_by('idcrud', 'DESC')->limit(5, $opset)->get();
if ($ambil->num_rows() > 0) {
foreach ($ambil->result() as $data) {
$hasil[] = $data;
}
$ambil->free_result();
return $hasil;
}
}
Controllers:
function suratkeluar($opset=NULL)
{
$result_per_page = 2; // the number of result per page
$config['base_url'] = base_url('Chome/suratkeluar');
$config['total_rows'] = $this->Mcrud->record_count();
$config['per_page'] = $result_per_page;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$data['data_get'] = $this->Mcrud->view($opset);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('Vhome', $data);
$this->load->view('Footer');
}
work for me :)
This question already has answers here:
pagination does not change page
(3 answers)
Closed 9 years ago.
hi everyone i am having some problems in displaying my pagination for some reason the pagination dose not appear on the page can some one help me out here is my code :
view
<div>
<table border="1">
<tr>
<th>Name</th>
<th>Second Name</th>
<th>Phone</th>
<th>Email</th>
<th>Answer</th>
<th>Comment</th>
</tr>
<?php foreach ($query as $row): ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->second_name; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
<td> <?php echo $row->answerA;?>
<?php echo $row->answerB;?>
<?php echo $row->answerC;?></td>
<td><?php echo $row->comment;?><br></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>
controller
<?php
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/Surva/index.php/result_controller/getall';
$config['total_rows'] = $this->db->get('tblanswers')->num_rows();
$config['per_page'] = 1;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('tblanswers', $config['per_page'], $this->uri->segment(1, 0))->result_array();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('result_view', $data);
}
i used the codeigniter guide and also a tutorial that i found on nettuts any help will be greatly appreciated tnx in advance.
Do like this
$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();