|
关于表单数据(post方法)无法重复在分页里获取的
controller代码
PHP复制代码
<?php
// defined('BASEPATH') OR exit('No direct script access allowed');
class Browse extends CI_Controller
{
private $data = array();
private $name, $book;
function __construct ()
{
parent ::__construct ();
$this->load->helper('Brophp');
$this->load->database("default");
// 加载分页
$this->load->library('pagination');
$this->load->helper('url');
// 获取词典名
$this->book = trim($this->input->post('book'));
}
public function index ()
{
$page_size = 20;
//偏移量
$offset = intval($this->uri->segment(4));
//限制
$this->db->limit($page_size, $offset);
//加载模型 获取数据
$this->load->model('Browse_model','Bml');
$this->data['words'] = $this->Bml->send_word($this->book);
// 每页20条数据
[align =left ][color =rgb (54, 54, 54)][backcolor =transparent ][font =-apple -system,BlinkMacSystemFont ,Helvetica Neue ,Helvetica ,Arial ,PingFang SC ,Hiragino Sans GB ,WenQuanYi Micro Hei ,Microsoft Yahei ,sans -serif ][size =14px ] $config['per_page'] = $page_size;[/size ][/font ][/backcolor ][/color ][/align ]
// 基本网址
$config['base_url'] = site_url ('word_machine/browse/index');
// 配置项选择
$num = count($this->data['words']);
$config['total_rows'] = 200; //???
echo $num;
$config['per_page'] = $page_size;
$config['uri_segment'] = 4; //4段
//其他配置就不一一显示
//var_dump($_REQUEST);
//初始化
$this->pagination->initialize($config);
$this->data['links'] =$this->pagination->create_links();
var_dump($this->data['links']);
// 加载视图
$template = 'word_machine/bigboss/browse';
$this->load->view($template, $this->data);
}
}
复制代码
model代码
PHP复制代码
class Browse_model extends CI_Model{
//private $book;
public function send_word($book){
$condition['book'] = $book;
$this->db->where($condition);
$data = $this->db->order_by('number')->get('words')->result_array();
// 正排序
return $data;
}
复制代码
view关键代码
PHP复制代码
foreach ($words as $w)
{
if ($odd === 1)
{
echo '<tr class="odd">';
}
elseif ($odd === -1)
{
echo '<tr class="even">';
}
echo '<td>'.$w['word'].'</td>';
echo '<td>'.$w['symbol'].'</td>';
echo '<td> '.$w['category'].'   </td>';
echo '<td>'.$w['meaning'].'</td>';
echo '</tr>';
$odd *= -1;
echo '</div>';
}
复制代码
具体情况如图
在第一页可以获取,后面$this->book就为空了
|
|