简体   繁体   English

如何<a>在 CodeIgniter 分页</a>中将类名设置为<a>标记</a>

[英]How to set class name to <a> tag in CodeIgniter pagination

I need to set class name to <a> tag in CodeIgniter pagination.我需要在 CodeIgniter 分页中将类名设置为<a>标记。 CodeIgniter's $this->pagination->create_links(); CodeIgniter 的$this->pagination->create_links(); function creates links like this:函数创建这样的链接:

<a href="http://example.com/pages/3">3</a>

But, I need link like this:但是,我需要这样的链接:

<a href="http://example.com/pages/3" class="number">3</a>

How can I solve this problem?我怎么解决这个问题?

这是使用此代码的以下代码,您可以在 Code Ignitor 中的分页锚标记内添加该类

$config['attributes'] = array('class' => 'myclass');

Add添加

$config['anchor_class'] = 'class="number" ';

before

$this->pagination->initialize($config); 

2. This attributes will work in above version of CI 3.1 2.属性适用于 CI 3.1 以上版本

$config['attributes'] = array('class' => 'myclass');
 

NOTE: For More Refer: system/libraries/Pagination.php.注意:更多参考:system/libraries/Pagination.php。 You will find below lines..你会发现以下几行..

// Deprecated legacy support for the anchor_class option // 弃用了对 anchor_class 选项的旧支持

// Should be removed in CI 3.1+ // 应该在 CI 3.1+ 中删除

1. This configuration is deprecated below (CI 3.1) version. 1.此配置在 (CI 3.1) 版本以下已弃用

$config['anchor_class'] = 'number';

From CodeIgniter's manual on the Pagination class :来自 CodeIgniter 的Pagination 类手册

Adding a class to every anchor为每个锚点添加一个类

If you want to add a class attribute to every link rendered by the pagination class, you can set the config "anchor_class" equal to the classname you want.如果您想为分页类呈现的每个链接添加一个类属性,您可以将配置“anchor_class”设置为您想要的类名。

So you simply write所以你只需写

$config['anchor_class'] = 'class="number"';
$this->pagination->initialize($config); 

before you use the pagination.在使用分页之前。


If you want to change this globally:如果要全局更改此设置:

If you prefer not to set preferences using the above method, you can instead put them into a config file.如果您不想使用上述方法设置首选项,则可以将它们放入配置文件中。 Simply create a new file called pagination.php, add the $config array in that file.只需创建一个名为 pagination.php 的新文件,在该文件中添加 $config 数组。 Then save the file in: config/pagination.php and it will be used automatically.然后将文件保存在:config/pagination.php,它将被自动使用。 You will NOT need to use the $this->pagination->initialize function if you save your preferences in a config file.如果您将首选项保存在配置文件中,则不需要使用 $this->pagination->initialize 函数。


Edit: CodeIgniters Pagination library behaves a bit inconsistent.编辑:CodeIgniters 分页库的行为有点不一致。

When using the $this->pagination->initialize($config);当使用$this->pagination->initialize($config); manually, you need to specify the attribute on your own:手动,您需要自己指定属性:

$config['anchor_class'] = 'class="number"';

However, when using the config-file, it is added automatically, so you have to use但是,在使用配置文件时,它是自动添加的,因此您必须使用

$config['anchor_class'] = 'number';

请尝试在锚标记上添加类的这一行代码

$config['attributes'] = array('class' => 'page-link');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM