我在Controller中有这个功能,从模型中调用所有项目并在主页中进行分页,所以我称之为主页:
http://localhost/cart/index.php/
转到下一页时显示此错误:
404 Page Not Found
我的控制器: -
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);
}
和模型:
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;
}
并查看:
<!-- Show pagination links -->
<p style="float:left"><?php echo $links; ?></p>
错误在哪里?
答案 0 :(得分:0)
在控制器中
$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);
在模型中
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;
}
config/config.php
中的
$config['base_url'] = '';
$config['index_page'] = '';
在.htaccess
(位于applicatino文件夹之外)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>