【发布时间】:2012-10-17 10:07:57
【问题描述】:
已解决!
如果我点击第 2 页,那就是错误:
未找到 在此服务器上未找到请求的 URL /rank/GetAll/30。
我的链接是:
http://localhost/rank/GetAll/30
模型:Rank_Model
<?php
Class Rank_Model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function record_count() {
return $this->db->count_all("ranking");
}
public function fifa_rank($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get("ranking");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
?>
控制器:等级
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class rank extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->helper(array('form', 'url'));
$this->load->model('Rank_Model','',TRUE);
$this->load->library("pagination");
}
function GetAll() {
$config = array();
$config["base_url"] = base_url() . "rank/GetAll";
$config["total_rows"] = $this->Rank_Model->record_count();
$config["per_page"] = 30;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Rank_Model->fifa_rank($config["per_page"], $page);
$data['errors_login'] = array();
$data["links"] = $this->pagination->create_links();
$this->load->view('left_column/open_fifa_rank',$data);
}
}
查看打开:open_fifa_rank
<?php
$this->load->view('mains/header');
$this->load->view('login/loggin');
$this->load->view('mains/menu');
$this->load->view('left_column/left_column_before');
$this->load->view('left_column/menu_left');
$this->load->view('left_column/left_column');
$this->load->view('center/center_column_before');
$this->load->view('left_column/fifa_rank');
$this->load->view('center/center_column');
$this->load->view('right_column/right_column_before');
$this->load->view('login/zaloguj');
$this->load->view('right_column/right_column');
$this->load->view('mains/footer');
?>
和查看:fifa_rank
<table>
<thead>
<tr>
<td>Pozycja</td>
<td>Kraj</td>
<td>Punkty</td>
<td>Zmiana</td>
</tr>
</thead>
<?php
foreach($results as $data) {?>
<tbody>
<tr>
<td><?php print $data->pozycja;?></td>
<td><?php print $data->kraj;?></td>
<td><?php print $data->punkty;?></td>
<td><?php print $data->zmiana;?></td>
</tr>
<?php } ?>
</tbody>
</table>
<p><?php echo $links; ?></p>
也许你知道我的问题在哪里?
现在我知道我的问题出在哪里了。 在第一页我有链接:
http://localhost/index.php/rank/GetAll
但在下一个:
http://localhost/rank/GetAll/30
在第二个链接中,我没有 index.php。我该如何解决?
在 $config["base_url"] = base_url() 中。 “排名/GetAll”; 我加 : $config["base_url"] = base_url() 。 "index.php/rank/GetAll";
没关系:)
【问题讨论】:
-
第一个页面的url是什么样的?您的重写规则是否有效,以便您可以使用没有
index.php的网址? -
现在我知道我的问题出在哪里了。在第一页我有链接:localhost/index.php/rank/GetAll 但在下一个:localhost/rank/GetAll/30 在第二个链接中,我没有 index.php。我该如何解决?
-
尝试在 Controller 的
GetAll方法中使用site_url而不是base_url。 -
@marcin_poland - 如果您已经解决了自己的问题,最好写一个新的答案来详细说明您的修复。不要忘记投票任何有用的答案!
标签: php codeigniter pagination segment