Php 找不到codeigniter分页404
我正在尝试使用codeigniter 3和引导twitter的分页。当我点击链接分页,它总是给我404找不到 我认为这是我没有完全理解codeigniter URI的错,这就是为什么我需要代码方面的帮助 这是我的模型:Php 找不到codeigniter分页404,php,codeigniter,pagination,Php,Codeigniter,Pagination,我正在尝试使用codeigniter 3和引导twitter的分页。当我点击链接分页,它总是给我404找不到 我认为这是我没有完全理解codeigniter URI的错,这就是为什么我需要代码方面的帮助 这是我的模型: class Mcrud extends CI_Model { public function record_count() { return $this->db->count_all("crud"); } function
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;
}
}
这是我的控制器:
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');
}
这是我的观点:
<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>
<a href="<?php echo site_url('Chome/edit/' . $row->idcrud); ?>" class="btn btn-warning btn-xs"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a href="<?php echo site_url('Chome/delete/' . $row->idcrud); ?>" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
<?php
}
}
?>
</tr>
</tbody>
</table>
<?php echo $pagination; ?>
</div>
最后这是我在config.php中的基本url:
$config['base_url']= 尝试修改本节: 型号:
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;
}
}
控制器:
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');
}
为我工作:你使用404的URL是什么?您是否尝试过$config['base\u url']=site\u url而不是$config['base\u url']=base\u url?总是得到404错误。感谢你,网站的url正在运行:D,不再出现404错误。我不知道有什么区别。现在我被卡住了,为什么在我点击那个链接后结果没有改变,因为你的查询不是动态的,看看你的限制语句。@Craig它不正确,删除那个注释。因为你们在那个里发布的url函数,比如site\uURL和base\uURL,都是在配置文件之后实例化的。事实上,base_url和site_url使用$config['base_url']可用。您的建议将导致致命错误:调用undefined函数。@A.P,但我已经测试过了,site_url正在工作。基本url总是给我404。我确信100%我已经自动加载“url”,我只需要创建动态限制操作集,对吗?出于某种原因,奇怪的是,不为我工作。。不太好,我。。。我已经直接去了你的仓库,咕哝着又闲了。。。。祝你好运:它现在工作了,我只需要设置$opset=$this->uri->segment3;感谢您的帮助:您需要选择,使用$offset参数为NULL或添加$this->uri->segment3;