Welcome Guest, Not a member yet? Register   Sign In
Pagination Class: page2 link not working on CI3
#1

I'm upgrading to CI3 the only piece I have ever developed using CI. Everything works well, except the pagination. I have 42 rows divided into two pages of 21 rows each. The link to the second page opens up the 404 page. I copy below the relevant controller and model. Any pointers as to what I should be looking into in order to fix the problem will be greatly appreciated. Thanks a lot.

Code:
<?php
class Frontps extends CI_Controller {
    
    function index($sort_by = 'Number', $sort_order = 'asc', $offset = 0) {
        
        $limit = 21;
        $data['fields'] = array(
            'Number' => 'Number',
            'Name' => 'Process',
            'area_name' => 'Area',
            'group_name' => 'Group',
            'process_weight' => 'Weight'
        );
        
        $data['fields2'] = array(
            'Number' => 'Number',
            'Name' => 'Process',
            'area_number' => 'Area',
            'group_number' => 'Group',
            'process_weight' => 'Weight'
        );
        
        $this->load->model('frontps_model');
        
        //search() comes from model
        
        $results = $this->frontps_model->search($limit, $offset, $sort_by, $sort_order);
        
        $data['res'] = $results['rows'];
        $data['num_results'] = $results['num_rows'];
        // pagination
        $this->load->library('pagination');
        $config = array();
        $config['base_url'] = site_url("index/$sort_by/$sort_order");
        $config['total_rows'] = $data['num_results'];
        $config['per_page'] = $limit;
        $config['next_link'] = '&gt;';
        $config['prev_link'] = '&lt;';
        $config['cur_tag_open'] = '<b>';
        $config['cur_tag_close'] = '</b>';
        $config['uri_segment'] = 4;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        
        $data['sort_by'] = $sort_by;
        $data['sort_order'] = $sort_order;

        
        $this->load->view('templates/pheader', $data);
        $this->load->view('processes/frontp', $data);
        $this->load->view('templates/pfooter', $data);
    }
    
    public function viewproc($process)
    {
    $this->load->model('processes_model');
    $process=$this->uri->segment(1);
    $number=$this->uri->segment(2);
    $data['pro'] = $this->processes_model->get_pro($number);
    
    if ( ! file_exists('application/views/processes/'.$process.'.php'))
    {
        show_404();
    }
    
    $data['title'] = ucfirst($process); // Capitalize the first letter
    
    $this->load->view('templates/pheader', $data);
    $this->load->view('processes/'.$process, $data);
    $this->load->view('templates/pfooter', $data);

    }
    
    public function viewprod($product)
    {
    $this->load->model('products_model');
    $product=$this->uri->segment(1);
    $number=$this->uri->segment(2);
    $data['prod'] = $this->products_model->get_prod($number);
    
    if ( ! file_exists('application/views/products/'.$product.'.php'))
    {
        show_404();
    }
    
    $data['title'] = ucfirst($product); // Capitalize the first letter
    
    $this->load->view('templates/pheader', $data);
    $this->load->view('products/'.$product, $data);
    $this->load->view('templates/pfooter', $data);

    }
    
}


Code:
<?php
class Frontps_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }
    
    function search($limit, $offset, $sort_by, $sort_order) {
        
        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
        $sort_columns = array('Number', 'Name', 'area_number', 'group_number', 'process_weight');
        $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'Number';
        
        // results query
        $q = $this->db->select('Process.process# as Number, Process.processName as Name, Process.processWeight as process_weight, Group.group# as group_number,
        Group.groupName as group_name, K_Area.kArea# as area_number, K_Area.kAreaName as area_name')
            ->from('Process')
            ->join('Group','Process.groupkey=Group.group#')
            ->join('K_Area','Process.kAreaKey=K_Area.kArea#')
            ->limit($limit, $offset)
            ->order_by($sort_by, $sort_order)
            ->order_by("Number", "asc");
        
        $ret['rows'] = $q->get()->result();
        
    //count query
        $q = $this->db->select('COUNT(*) as count', FALSE)
            ->from('Process');
        
        $tmp = $q->get()->result();
        
        $ret['num_rows'] = $tmp[0]->count;
        
        return $ret;
    }
    
    
}
Reply
#2

Problem solved  Blush (embarrassed)

I was stuck for a while looking for differences between CI_v2 and CI_v3 in order to pinpoint the problem. The original code (2012) worked well in v2. Why wasn't it working on v3?. I installed a debugging resource (Firefox, firebug, and firePHP), and after a few tests I realized that in the upgrade I had omitted activating two important helpers: array_helper.php and html_helper.php. Embarrassing. My only possible justification, if any, is that after 3 years, and despite the comments interspersed in the code, I lost all familiarity with what I had done. The debugging resource, excellent tool, was key to find out what was happening. I apologize. I'll upload the upgraded application and post the link for anyone to look at if interested.
Reply
#3

(06-29-2015, 07:19 PM)raulcid Wrote: Problem solved  Blush (embarrassed)

I was stuck for a while looking for differences between CI_v2 and CI_v3 in order to pinpoint the problem. The original code (2012) worked well in v2. Why wasn't it working on v3?. I installed a debugging resource (Firefox, firebug, and firePHP), and after a few tests I realized that in the upgrade I had omitted activating two important helpers: array_helper.php and html_helper.php. Embarrassing. My only possible justification, if any, is that after 3 years, and despite the comments interspersed in the code, I lost all familiarity with what I had done. The debugging resource, excellent tool, was key to find out what was happening. I apologize. I'll upload the upgraded application and post the link for anyone to look at if interested.

I have same problem...
please tell me how to fix it? 
Reply
#4

I have same problem... Please tell me how to fix it?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB