我正在尝试将分页放入我的 CodeIgniter 项目中。我已经仔细按照说明进行操作,我确实设法加入表格并将它们显示在我的“mahasiswa_view”中,但是当我尝试将它与分页结合使用时,它显示错误:
这是我的控制器代码 = "home" :
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('modelku');
}
function index($offset = NULL)
{
//pagination
$limit = 3;
if(!is_null($offset))
{
$offset = $this->uri->segment(3);
}
$this->load->library('pagination');
$config['uri_segment'] = 3;
$config['base_url'] = site_url('home/index');
$config['total_rows'] = $this->modelku->total_record_mahasiswa();
$config['per_page'] = $limit;
$config['num_links'] = 5;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
//$data['mahasiswa']=$this->modelku->get_mahasiswa_all();
$data['mahasiswa'] = $this->modelku->get_mahasiswa_all($limit,$offset);
$this->load->view('mahasiswa_view',$data);
}
这是我的模型代码=“modelku”:
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Modelku extends CI_Model
{
//pagination
function total_record_mahasiswa()
{
return $this->db->count_all('tb_mahasiswa','tb_prodi');
//return $this->db->count_all('tb_mahasiswa');
}
function get_mahasiswa_all($limit,$offset)
{
$this->db->select('tb_mahasiswa.nim, tb_mahasiswa.nama, tb_mahasiswa.tanggal_lahir,
tb_mahasiswa.jenis_kelamin, tb_mahasiswa.alamat, tb_mahasiswa.propinsi,
tb_mahasiswa.telepon, tb_mahasiswa.email, tb_mahasiswa.photo,
tb_mahasiswa.prodi,
tb_prodi.namaprodi');
$this->db->from('tb_mahasiswa');
$this->db->join('tb_prodi','tb_mahasiswa.prodi=tb_prodi.kode');
//$query = $this->db->get();
$this->db->order_by('nim','ASC');
//$query = $this->db->get('tb_mahasiswa','tb_prodi',$limit, $offset);
$query = $this->db->get($limit, $offset);
return $query->result();
}
最后一个,我的观点 = 'mahasiswa_view' :
<!doctype html>
<html>
<head>
<title>PHP Framework</title>
<link rel="stylesheet" href="<?php echo base_url() ?>asset/css/style.css"/>
</head>
<body>
<h3>Selamat Datang di Form Mahasiswa</h3>
<table width="80%" border="1" >
<tr style="background-color:blue; color:white;">
<td> No. </td>
<td> NIM </td>
<td> Nama </td>
<td> Tanggal Lahir </td>
<td> Jenis Kelamin </td>
<td width="20%"> Alamat </td>
<td> Telepon </td>
<td> Email </td>
<td> Prodi </td>
<td> Photo </td>
</tr>
<?php if(isset($msg_error))
{
echo '<div style="color:red;">' . $msg_error.'</div>';
}
?>
<?php
echo anchor('home/login','Login');
$no=1;
foreach ($mahasiswa as $row)
{
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $row->nim . ' '; ?></td>
<td><?php echo $row->nama . ' '; ?></td>
<td><?php echo $row->tanggal_lahir . ' '; ?></td>
<td><?php echo $row->jenis_kelamin . ' '; ?></td>
<td><?php echo $row->alamat . ' '; ?></td>
<td><?php echo $row->telepon . ' '; ?></td>
<td><?php echo $row->email . ' '; ?></td>
<td><?php echo $row->namaprodi . ' ';?></td>
<td><?php echo $row->photo . ' </br>';?></td>
</tr>
<?php
$no++;
}
?>
 
<form action="<?php print site_url();?>/home/cari" method=POST>
<input type=text name=cari> <input type=submit value="Cari">
</form>
</table>
<?php
echo "<br /><div>" .$this->pagination->create_links() ."</div>";
?>
</body>
</html>
我还是 CodeIgniter 的新手,所以任何帮助都将不胜感激。