A codeword

Can anyone tell me what wahat did wrong. I am writing the pagination code using the pagination library and everything works fine except for the pagination links that nobody needs. they just add additional uri paths like http: // localhost: 8081 / web / index.php / Public / Main / index / 1/1/1 when clicked. Help me please.

application / core / My Controller

public function PAGINATE($total, $per_page) {
        $this->load->library('pagination');
        $config["base_url"] =   $_SERVER['PHP_SELF'];
        $config["total_rows"] = $total;
        $config["per_page"] = $per_page;
        $config["uri_segment"] = 3;
        $config["num_links"] = 3;
        $config['prev_link'] = 'Previous';
        $config['next_link'] = 'Next';
        $config['last_link'] = 'Last';
        die(print_r($config));
        $this->pagination->initialize($config);
        $this->data["links"] = $this->pagination->create_links();
    }

      

Controllers / Public / Home / Index

public function index()
    {
        parent::PAGINATE(sizeof($this->data['homes'] = $this->AppModel->get_all(HOME_TABLE, 200, 0)), 1);
        parent::RENDER('Public/Site/Home');
    }

      

Model

 public function get_all($table, $limit, $offset){
        $this->db->select('*');
        $this->db->limit($limit, $offset);
        $this->db->from($table);
        $query = $this->db->get();
        return $query->result_array(); // fetch data

    }

      

View

<div class="page-nav">
                <ul>
                    <li><?php echo $links; ?></li>
                </ul>
            </div>

      

+3


source to share


1 answer


$config["base_url"] =   $_SERVER['PHP_SELF'];

      

This line should be replaced with the following

$config["base_url"] =   site_url('public/main/index');
//$config["base_url"] =   'http://localhost:8081/web/index.php/Public/Main/index';//you can use this too

      

Make sure you download a helper URL

to use the feature site_url

.



If you want to see the page number instead of the post number in the link, you can use

$config['use_page_numbers'] = true;

      

To get complete records in a database, you must use.

return $this->db->count_all_results($table);  

      

+1


source







All Articles