【问题标题】:pagination links will not work分页链接不起作用
【发布时间】:2014-12-09 03:53:35
【问题描述】:

在我的用户索引页面上,我正在尝试设置 CI 分页。但是当我点击第二个链接时会加载一个错误页面“无法加载页面”;我花了一整天的时间,不会在同一页面上加载。我使用 hmvc 不知道会不会有影响?

我怎样才能让它在同一页面上加载。正如我看过的大多数教程所示。喜欢 tuts plus 教程。

$config['base_url'] = 'http://localhost/codeigniter-project/';

网址 http://localhost/codeigniter-project/admin/users/

路线 $route['admin/users'] = "admin/user/users/index";

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends MX_Controller {
public function __construct() {
parent::__construct();
  $this->lang->load('admin/user/users', 'english');
  $this->load->model('admin/user/users_model');

  if (!$this->user->logged()) {
   redirect('admin');
  }
}

public function index() {
$this->document->setTitle($this->lang->line('heading_title'));

$data['heading_title'] = $this->lang->line('heading_title');

$this->load->library('setting'); 

$this->load->library('pagination'); 

$config = array(); 

$config["base_url"] = base_url('admin/users'); 
$config['total_rows'] = $this->db->get('user')->num_rows(); 
$config["per_page"] = $this->setting->get('config_limit_admin'); 
$config["uri_segment"] = 3;  

$this->pagination->initialize($config);
$data['user'] = $this->db->get('user', $config["per_page"], $this->uri->segment(3));

return $this->load->view('user/users_list', $data);
}
}

查看

<?php echo Modules::run('admin/common/header/index');?><?php echo Modules::run('admin/common/column_left/index');?>

<div id="content">
<div class="container-fluid">


<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php if ($this->session->flashdata('error')) { ?>
<div class="alert alert-danger"><i class="fa fa-times-circle"></i> <?php echo $this->session->flashdata('error');?></div> 
<?php } ?>
<?php if ($this->session->flashdata('success')) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $this->session->flashdata('success');?></div> 
<?php } ?>
</div>
</div>

<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><?php echo $heading_title; ?></h3></div>
<div class="panel-body">

<?php  

echo '<div class="table-responsive">';
echo '<table class="table table-striped table-bordered table-hover">';
echo '<thead>';
echo '<tr>';
echo '<td class="text-center">' . "User ID" . '</td>';
echo '<td class="text-center">' . "Username" . '</td>';
echo '<td class="text-center">' . "Status" . '</td>';
echo '<td class="text-center">' . "Date Added" . '</td>';
echo '<td class="text-center">' . "Action" . '</td>';
echo '</tr>';
echo '</thead>';

foreach ($user->result() as $row) {

echo '<tbody>';
echo '<tr>';
echo '<td class="text-center">' . $row->user_id  .'</td>';
echo '<td class="text-center">' . $row->username  .'</td>';
echo '<td class="text-center">' . $row->status  .'</td>';
echo '<td class="text-center">' . $row->date_added  .'</td>';
echo '<td class="text-center">' . anchor("admin/users/edit/" . $row->user_id, '<div class="btn btn-primary text-right" role="button"><i class="fa fa-pencil"></i>
 Edit</div>')  .'</td>';
echo '</tr>';
echo '</tbody>';

}

echo '</table>';
echo '</div>';
echo '<div class="row">';
echo '<div class="col-sm-6 text-left">';
echo $this->pagination->create_links();
echo '</div>';
echo '</div>';

?>

</div><!-- . Panel Panel-Body -->
</div><!--  . Panel Panel-Default -->
</div><!-- . Columns -->
</div><!-- . Row -->
</div><!-- . Container-fluid-->
</div><!-- #Content -->

<?php echo Modules::run('admin/common/footer/index');?>

【问题讨论】:

  • 浏览器在那些“无法加载”页面上加载的 URL 是什么?
  • 1: link http://localhost/codeigniter-project/index.php/admin/users2 link: http://localhost/codeigniter-project/admin/users/index/1 显示无法加载页面

标签: codeigniter


【解决方案1】:

我刚刚头脑风暴并添加了$route['admin/users/(:num)'] = "admin/user/users/index/$1";,现在链接可以工作了。

【讨论】:

    猜你喜欢
    • 2018-06-25
    • 1970-01-01
    • 2014-02-03
    • 2021-01-11
    • 2014-04-10
    • 2013-09-06
    • 1970-01-01
    相关资源
    最近更新 更多