I have this function in Controller that call all item from model and make pagination in home page, So i call home page like :
http://localhost/cart/index.php/
When go to next page show me this error :
404 Page Not Found
My controller :-
public function index() {
$config = array();
$config["base_url"] = base_url() . "index.php";
$config["total_rows"] = $this->main_model->record_count();
$config["per_page"] = 8;
$config["uri_segment"] = 2;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["home_products"] = $this->main_model->fetch_items($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data['categories'] = $this->main_model->getAllCategories();
$this->load->view("home", $data);
}
and the model :
public function record_count() {
return $this->db->count_all("wg_items");
}
public function fetch_items($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get("wg_items");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
and view :
<!-- Show pagination links -->
<p style="float:left"><?php echo $links; ?></p>
Where is error ??
In controller
$count = $this->main_model->record_count();
$config = array();
$config["base_url"] = base_url() .'index.php/Front/index';
$config["total_rows"] = $count ;
$config["per_page"] = 8;
$config["uri_segment"] = 3;
$limit = $config['per_page'];
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['home_products'] = $this->main_model->get_item($page,$limit);
in model
public function get_item($page,$limit)
{
$query = $this->db->query("SELECT * FROM table name LIMIT $page, $limit");//your argument
$result = $query->result_array();
return $result;
}
in config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
in .htaccess
(Place outside of applicatino folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.