如何在没有配置的情况下设置分页链接的样式 - codeigniter
Posted
技术标签:
【中文标题】如何在没有配置的情况下设置分页链接的样式 - codeigniter【英文标题】:how to style pagination links without config - codeigniter 【发布时间】:2015-07-17 18:46:52 【问题描述】:我有以下分页样式
<ul class="pagination">
<li><a href="#"><i class="fa fa-long-arrow-left"></i>Previous Page</a></li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">Next Page<i class="fa fa-long-arrow-right"></i></a></li>
</ul><!--/.pagination-->
我想在不使用配置的情况下使上述静态代码动态
<ul class="pagination">
<?php echo $this->pagination->create_links(); ?>
</ul><!--/.pagination-->
控制器
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = "</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
【问题讨论】:
样式表示CSS
或者你想把ul li改成div等?
我只是想让上面的静态代码动态化...类必须相同
你能分享你的控制器方法吗?你试过$this->pagination->initialize($config);
吗?在配置数组中你可以定义所有的开始和结束标签。
更新了控制器代码
请检查答案我已经更新了您的分页的下一个和上一个链接。
【参考方案1】:
好的,我试过了,这个控制器代码工作正常
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$this->pagination->initialize($config);
查看
<?php echo $this->pagination->create_links(); ?>
【讨论】:
【参考方案2】:在您的控制器中添加此配置。
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next Page';
$config['next_tag_open'] = '<li><i class="fa fa-long-arrow-right"></i>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = 'Previous Page';
$config['prev_tag_open'] = '<li><i class="fa fa-long-arrow-left"></i>';
$config['prev_tag_close'] = '</li>';
$this->pagination->initialize($config);
在你看来只是回显分页
<?php echo $this->pagination->create_links(); ?>
删除ul
【讨论】:
【参考方案3】:控制器
public function moreNews($pid = 0) $config['base_url'] =
base_url('index.php/MainController/morenews'); $config['total_rows']
= 200; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination">'; $config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = "<li class='page-item'>";
$config['first_tag_close'] = "</li>"; $config['prev_tag_open'] =
"<li class='page-item'>"; $config['prev_tag_close'] = "</li>";
$config['next_tag_open'] = "<li class='page-item'>";
$config['next_tag_close'] = "</li>"; $config['last_tag_open'] = "<li
class='page-item'>"; $config['last_tag_close'] = "</li>";
$config['cur_tag_open'] = "<li class='page-item'><a class='page-link
active' href=''>"; $config['cur_tag_close'] = "</a></li>";
$config['num_tag_open'] = "<li class='page-item'>";
$config['num_tag_close'] = "</li>"; $config['attributes'] =
array('class' => 'page-link');
$this->pagination->initialize($config); $data['pagination'] =
$this->pagination->create_links(); $data['news'] =
$this->MainModel->paginationpage($pid); $data['news']=
$this->MainModel->get_news(); //echo '<pre>'; // print_r($data);
$this->load->view('morenews', $data); `.
型号
function paginationpage($pid) $count=1;
$this->db->select('*')->from('_news')->limit($count, $pid,
$pid+$count); $query=$this->db->get(); return
$query->result_array(); `.
【讨论】:
以上是关于如何在没有配置的情况下设置分页链接的样式 - codeigniter的主要内容,如果未能解决你的问题,请参考以下文章
如何在没有样式化所有其他选项的情况下使用 CSS 样式选择选项?
如何使用 bootstrap 4 默认分页样式获得 laravel 分页链接?