分页在带有 url_suffix 的 codeigniter 2.1.0 中无法正常工作
我正在使用 codeigniter 2.1.0 和 mysql 数据库。在我的管理面板中,我有一个页面,我想在其中向所有用户显示分页视图。但它不起作用。尝试了很多事情之后
这是我的更新代码
控制器:
function accounts() // controller to view all users
{
$this -> load -> library('pagination');
$config['base_url'] = site_url('admin/home/accounts/');
$config['total_rows'] = $this->db->get('user')->num_rows();
$config['per_page'] = 2;
$config['num_links'] = 2;
$config['full_tag_open'] = '<p id="pagination">';
$config['full_tag_close'] = '</p>';
$offset = $this->uri->segment(4,0);
$this->pagination->initialize($config);
$this->load->model('admin_model');
$data['user_data']=$this->admin_model->all_user($config['per_page'],$offset);
$data['links']=$this -> pagination -> create_links();
$data['main_content']='admin/accounts';
$this->load->view('includes/admin/admin_template',$data);
}
视图:
<?php foreach ($user_data as $data) {?>
<?php echo 'Name:' . ' ' ?>
<?php echo ($data['name']).'<br/>'; ?>
<?php echo 'E-mail:' . ' ' ?>
<?php echo ($data['email']).'<br/>'; ?>
<br />
<?php } ?>
<?php echo $links;?>
模型:
function all_user($per_page,$offset) //shows all uer info
{
$query = $this->db->get('user', $per_page, $offset);
$row=$query->result_array();
return $row;
}
这是路线:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['admin']='admin/admin';
我使用.htaccess mod_rewrite删除我的index.php并使用$config['url_suffix']='.html'添加后缀.html 使网址看起来像这样'http://localhost/project/admin/home/accounts.html'
而不是'http://localhost/project/index.php/admin/home/accounts'
但是如果我删除 config.php 中的 url_suffix
*/
$config['url_suffix'] = '';
/*
分页工作正常。但我想使用 url_suffix
*/
$config['url_suffix'] = '.html';
/*
但如果我这样做,分页不起作用,并显示 404 页面未找到错误。我该如何解决这个问题?
i am using codeigniter 2.1.0 and mysql database. in my admin panel i have a page where i want to show all users with a paginating view. but it is not working. after trying a lot of things
here is my updated code
controller:
function accounts() // controller to view all users
{
$this -> load -> library('pagination');
$config['base_url'] = site_url('admin/home/accounts/');
$config['total_rows'] = $this->db->get('user')->num_rows();
$config['per_page'] = 2;
$config['num_links'] = 2;
$config['full_tag_open'] = '<p id="pagination">';
$config['full_tag_close'] = '</p>';
$offset = $this->uri->segment(4,0);
$this->pagination->initialize($config);
$this->load->model('admin_model');
$data['user_data']=$this->admin_model->all_user($config['per_page'],$offset);
$data['links']=$this -> pagination -> create_links();
$data['main_content']='admin/accounts';
$this->load->view('includes/admin/admin_template',$data);
}
view:
<?php foreach ($user_data as $data) {?>
<?php echo 'Name:' . ' ' ?>
<?php echo ($data['name']).'<br/>'; ?>
<?php echo 'E-mail:' . ' ' ?>
<?php echo ($data['email']).'<br/>'; ?>
<br />
<?php } ?>
<?php echo $links;?>
model:
function all_user($per_page,$offset) //shows all uer info
{
$query = $this->db->get('user', $per_page, $offset);
$row=$query->result_array();
return $row;
}
and here is the route:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['admin']='admin/admin';
i have used the .htaccess mod_rewrite to remove my index.php and the $config['url_suffix']='.html' to add a suffix of .html which makes the url look like this'http://localhost/project/admin/home/accounts.html'
instead of'http://localhost/project/index.php/admin/home/accounts'
but if i remove the url_suffix in my config.php
*/
$config['url_suffix'] = '';
/*
the pagination works fine. but i want to use url_suffix
*/
$config['url_suffix'] = '.html';
/*
but if i do so, the pagination doesn't work, and shows 404 page not found error. how do i fix this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在您的代码中看到很多问题。但第一件事是第一。
将
您的查询放入偏移量中。
更新:如果您尚未完成
mod_rewrite
,请将 'index.php' 添加到您的$config['base_url']
中。例如
$config['base_url']=base_url().'index.php/admin/....';
在上面的代码中添加您的路径。
I see lots of issues in your code. But 1st thing 1st.
Put
in your query in the offset.
Update: if you haven't done
mod_rewrite
, then add 'index.php' to your$config['base_url']
.E.g.
$config['base_url']=base_url().'index.php/admin/....';
add your path in above code.
$config['base_url'] = site_url('admin/home/accounts');
在此行中,您需要在末尾添加一个 backslas,例如
$config['base_url'] = site_url( 'admin/home/accounts/');
更新
以您的方式将其添加到您的控制器
更新
虽然我对 codeigniter 知之甚少,但这是一个疯狂的想法。
在模型和控制器之间切换。您确定您所说的控制器是代码中的控制器吗?模型的问题相同。
更新
抱歉,您的基本网址应该是
$config['base_url'] = site_url('admin/home/accounts');
in this line you need a backslas at the end like
$config['base_url'] = site_url('admin/home/accounts/');
Update
add this to ur controller in your way
Update
A crazy idea though i know less about codeigniter.
Switch between your model and controller. Are you sure What you call controller is controller in your code? same ques for model.
Update
My apologies, your base url should be
在系统中-> Pagination.php 文件(默认设置)
$config['suffix'] ="example"
Url_suffix 用于分页.........
in system -> Pagination.php file (default settings)
$config['suffix'] ="example"
Url_suffix for your pagination ..........