分页在带有 url_suffix 的 codeigniter 2.1.0 中无法正常工作

发布于 2025-01-01 02:19:43 字数 2157 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝礼 2025-01-08 02:19:43

我在您的代码中看到很多问题。但第一件事是第一。

$this->uri->segment(4)

您的查询放入偏移量中。

更新:如果您尚未完成 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

$this->uri->segment(4)

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.

玉环 2025-01-08 02:19:43

$config['base_url'] = site_url('admin/home/accounts');

在此行中,您需要在末尾添加一个 backslas,例如

$config['base_url'] = site_url( 'admin/home/accounts/');

更新

以您的方式将其添加到您的控制器

$data['links']=$this->pagination->create_links();

更新
虽然我对 codeigniter 知之甚少,但这是一个疯狂的想法。

在模型和控制器之间切换。您确定您所说的控制器是代码中的控制器吗?模型的问题相同。

更新
抱歉,您的基本网址应该是

$config['base_url'] = site_url('admin/home/accounts/index/');

$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

$data['links']=$this->pagination->create_links();

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

$config['base_url'] = site_url('admin/home/accounts/index/');
笑着哭最痛 2025-01-08 02:19:43

在系统中-> Pagination.php 文件(默认设置)

class CI_Pagination {

var $base_url           = ''; // The page we are linking to
var $prefix             = ''; // A custom prefix added to the path.
var $suffix             = ''; // A custom suffix added to the path.
.
.
}

$config['suffix'] ="example"

Url_suffix 用于分页.........

in system -> Pagination.php file (default settings)

class CI_Pagination {

var $base_url           = ''; // The page we are linking to
var $prefix             = ''; // A custom prefix added to the path.
var $suffix             = ''; // A custom suffix added to the path.
.
.
}

$config['suffix'] ="example"

Url_suffix for your pagination ..........

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文