辅助函数:application/helper下面。命名要求为***_helper.php;这样在调用的时候
直接$this->load->helper('***');若想给自定义的辅助函数传参数:$config=函数名();以辅助函数分页为例子:
page_helper.php<?php function page($link_url,$total_nums,$page_num){ $config['base_url'] =$link_url; $config['total_rows'] = $total_nums; $config['per_page'] = $page_num; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $config['first_link'] = '首页'; $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['last_link'] = '末页'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['next_link'] = '下一页'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; $config['prev_link'] = '上一页'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['cur_tag_open'] = '<li class="current">'; $config['cur_tag_close'] = '</li>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['uri_segment'] = 4;将分页数据传输位置改为4 return $config;}
?>
在控制里面调用:
$page_num = '2';//每页显示的数目$this->load->model('Page_model');$data= $this->Page_model->page('tx_news',$page_num,$this->uri->segment(4),$id);//加载分页的控制器;$total_nums=count($news); $data['query']=$data[0]; $this->load->library('pagination');$config=page($this->config->item('base_url')."/index.php/News/index/{$id}",$total_nums,$page_num);$this->pagination->initialize($config);