Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Pagination | How add custom data to links ?
#1

[eluser]Noobigniter[/eluser]
Hello,

I'm stuck for a while on my pagination ...
In fact, everything seems to work normally but I can not pass data to the links

In my CONTROLLER:
Code:
// initialisation de la pagination
    $this->pagination->initialize(
        array(
            'base_url'         => base_url().($this->lang->lang()).'/news/page/',
            'total_rows'       => $this->News_model->count_news(),
            'per_page'         => NB_NEWS_PAR_PAGE,
            'use_page_numbers' => TRUE,
      
            // previous url
            'prev_link'        => FALSE,

            // current page
            'cur_tag_open'     => '<li class="active"><a href="[removed]void(0);">',
            'cur_tag_close'    => '</a></li>',

            // next url
            'next_link'        => FALSE,

            // all link
            'num_tag_open'     => '<li>',        
            'num_tag_close'    => '</li>',  
  
            'anchor_class'     => 'data-ajax="true" data-href="" ',
      
        )
    );
In my VIEW:
Code:
&lt;?php
if(isset($pagination)) :
     //superdump($pagination); // super var_dump
?&gt;
<div class="pagination pagination-centered">
     <ul>
                &lt;?php echo ($pagination);?&gt;
     </ul>
</div>

&lt;?php
endif;

OUTPUT :
Code:
<div class="pagination pagination-centered">
    <ul>
        <li class="active">&lt;!--a href="[removed]void(0);">1</a></li>
        <li>&lt;!--a data-ajax="true" data-href="" href="/fr/news/page/2">2</a></li>
    </ul>
</div>


As you can see, in 'anchor_class' I managed to add the data, but I'd add the same value of links in "data-href", because I use it throughout the site to view pages via Ajax.

PS: I added "!--" in <a> Tag because of the ban to post links from spam.
Thank Google for the translation ... 8-/


In advance, thank you !
#2

[eluser]Mauricio de Abreu Antunes[/eluser]
If you need to set a new value in anchor_class, try to create a variable in your controller, like:
Code:
$page = $this->uri->segmente(2); //Your number page segment.

In your anchor class, put your
Code:
data-href="fr/news/page/$page"

Smile
#3

[eluser]Noobigniter[/eluser]
Hum ..
It's not working because when i get the News page, URL is like this : example[dot]com/fr/news and there is not ID in the current url.

It is not possible to have the same value in HREF and DATA-HREF ?

Quote:CodeIgniter's Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.
Really or not !?


Regards.
#4

[eluser]Mauricio de Abreu Antunes[/eluser]
What are your custom data?
Smile
#5

[eluser]Mauricio de Abreu Antunes[/eluser]
Dude,

put your base_url variable here
Code:
data-href="$base_url_variable_here"
.

"but I’d add the same value of links in “data-href”..."

You can edit it with javascript too. But PHP is better in this case.

I hope i helped you!
#6

[eluser]Noobigniter[/eluser]
The links are generated like this:
Code:
<li><a href="http://domain[dot]be/fr/news/page/2">2</a></li>
And I need them like this:
Code:
<li><a href="http://domain[dot]be/fr/news/page/2" data-href="http://domain[dot]be/fr/news/page/2">2</a></li>

But I can't do Sad

Thank you for your help. :p
#7

[eluser]Noobigniter[/eluser]
SOLVED

Having found no other solutions, I directly modified the Codeigniter library pagination ...

Sorry for inconvenience :roll:
#8

[eluser]Aken[/eluser]
There is no way to add attributes to a link like that without extending the Pagination class, so you were correct in doing that. The only extra thing you can add is a class name (or names) to each anchor.

I'm curious why you need a data-html attribute that just duplicates the normal href? It's already in that attribute, so you should be able to access it via Javascript no problem.
#9

[eluser]Noobigniter[/eluser]
Ok, thank you for the clarification.

In fact, I use "data-href" because sometimes, despite the e.preventDefault(); in javascript, the user redirected to the evening, which is not really what I want.

In fact, if
Code:
$this->pagination->create_links($ajax = TRUE);
, I replace the URL with "[removed]void(0);" to prevent the problem mentioned above and I put the url in "data-href".

I do not know if what I'm trying to say is clear :/
#10

[eluser]Aken[/eluser]
You should use "return false" on links you don't want to process appropriately. You should also make sure there are no Javascript errors, which will prevent the JS from loading properly, and making your links function like normal.

I would't change the href feature to the void(0) script, because you're then alienating anyone who might have Javascript turned off - your site will be completely broken for them.




Theme © iAndrew 2016 - Forum software by © MyBB