CodeIgniter: Is possible to have current page link by pagination library? - php

I have created pagination item by CodeIgniter pagination library with following code:
echo $this->pagination->create_links()
Everything is working well.
Now i want to load data by ajax and i have done already ajax part. But problem is to make clicked item as a current item and to arrange link for current item as it is no longer current.
Suppose i have a pagination as following:
[1] 2 [3] [4] [5] [6] [>] [Last >]
Now 2 is current item and 4 is clicked item.
I have checked CodeIgniter Pagination library, but it doesn't have any option to enable or disable current page link. Is it possible to have current page link without modifying the library?
Thanks in advance.

I take it all back. The Pagination library will need to be changed.
https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Pagination.php
Line 560
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close
Will need to be replaced with
$append = $this->prefix.$i.$this->suffix;
$output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'.$loop.'</a>'.$this->num_tag_close;
That should do it.

You don't need to modify anything on server side. just use plain old vanila jquery.
Here's how to do it.
Let's say i wrapped the links in a <div id="pagination"></div>
Now, to call ajax, use jQuery(body).on('click','#pagination a', function(e){....}).
Here in this code, jQuery(this) will refer to the link that was clicked.
Next, after successful call, remove the active (or any other class that is given ) from all the links. like jQuery('#pagination a').removeClass('active').
Next, if you still remember, jQuery(this) still refered to the current clicked item. (better save it as var current = jQuery(this) at the start of the clicked even so that the reference does not change. Now, just add the class. jQuery(current).addClass('active')
You are done! No need to do anything fancy anything in server side. Sometimes client side is enough.
P.S. i forgot how CI renders the pagination links. if you give the links, i can write the actual code.

var_dump($this->pagination); everything is inside
then if you check Pagination.php library you have these params available too:
var $cur_tag_open = '';
var $cur_tag_close = '';
so try calling them when initializing pagination
$pagination['cur_tag_open'] = '<span class="current-link">';
$pagination['cur_tag_close'] = '</span>';
$this->pagination->initialize($pagination); //now current link should be wrapped into the <span class="current-link"></span>

I don't believe you need to change anything in the Pagination library. You just need to use the uri_segment() function.
The Pagination library takes an argument as follows:
$config['uri_segment'] = 5;
The default value is 3. [Use a value that will work with your URI structure].
This variable is used along with the uri_segment() function to determine the current page, in the latest version of CodeIgniter 2.1.4 you will find it starting on line 142 in the Pagination.php library.
The appropriate uri_segment for the page identifier could be calculated as follows, if using a URI like this one: http://example.com/controller/function/page/20 then you can get the current page as follows,
$page = $this->uri_segment(4);
Hope that helps.

You really dont need to change anything.
Once you have your automatic page set
$page = 2 // Page should be set automatically
Now try this
$config["cur_page"] = $page;

Related

get and add php variable in wordpress page

hi i create one custom page in WordPress like page-download.php
i access this page like
http://example.com/download
its word fine but i want access this page like
http://example.com/download?n=skype
http://example.com/download?n=firefox
etc every time n value change.
and also i want get n value in page-download.php
please tell me how to do it . i know how to work in php simple but in wordpress its not work
Why just not use, echo $_GET['n'] ?
When you hit this page directly from the URL like below, please change your parameter, because of that I have tried same method few days ago and I can't get the parameter value.
http://example.com/download?from_browser=skype
http://example.com/download?from_browser=firefox
You can get the value like below or as per the reference :
$blah = get_query_var( 'from_browser');
if(isset($blah)) // Your code will be here
Hope this help!!!

giving custom argument vlue in 'q' variable

**also posted on druapl.stackexchange
https://drupal.stackexchange.com/questions/150500/giving-custom-argument-vlue-in-q-variable
**
apologies if question is ambiguous . the scenario is as follows:
in drupal 7 , we want to use a custom template page when a specific value is given for the q variable in url .
for example if we give http://localhost/drupal/?q=xyz/123 , we want to use a custom template page say page-xyz.tpl.php ..
have a hunch that hooks and template.php file may be the key components here but not sure what to exactly do..
any help appreciated.
you could implement theme_preproccess_page() (or node, or html) to control this in your template.php
function YOURTHEME_preproccess_page(&$vars) {
if (isset($_GET['q']) && $_GET['q'] == 'xyz/123') {
$vars['theme_hook_suggestions'][] = 'page_xyz';
}
}
that should work, but I would like to recommend not use the '?q=xyz' solution, but do an preproccess that should work to all your pages, like this.
function YOURTHEME_preproccess_page(&$vars) {
$title = strreplace(' ','_', $vars['node']->title);
//if you use the transliteration module, instead of strreplace
//use transliteration_get($vars['node']->title);
$vars['theme_hook_suggestions'][] = 'page_'.$title;
}
now that should work for every page that you want to make a custom template. Just add the file and clear the chaches. If you don't have the page template to the specific page, it's ok, drupal will use the default.

CodeIgniter Pagination - first page’s link doesn’t work, why?

I use pagination library on my site, my config is here:
$data['url_keyword'] = url_title($keyword, '_');
$config['base_url'] = base_url().'image/'.$data['url_keyword'].'/';
$config['per_page'] = 1;
$config['uri_segment']=3;
my urls are: mysite/image/keyword/1 (page2), mysite/image/keyword/2 (page3), mysite/image/keyword/3 (page4), mysite/image/keyword/4 (page5)
When I’m on page 2 (mysite/image/keyword/1) and click previous - it gets me into mysite/image/keyword/ - which doesnt work, but mysite/image/keyword/0 WORKS. Library just doesn’t add zero at the end of url.
how to fix it?
Try this:
if (!$this->uri->segment(3))
$page = 0;
//Your other logic
By default if $this->uri->segment(x) is empty it will return false.
Without seeing your controller or view I can't be more specific on where to place this or what you are naming your variable. This should work in the instances in which you call: yoursite.com/image/keyword

CodeIgniter Pagination : Does not create first page's link

my pagination problem still continue ;
I just making pagination in simple stuff :
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config)
And my view page has this command for view pagination :
<?php echo $this->pagination->create_links(); ?>
And after more than 20 rows , pagination starts to paging the list, but html output shows like this :
1 2 3
As in view , First Page Number 1 does not have link either jumping next page , there is no link on page number 1. Just its on strong .
My second problem is : I have just 30 record but CI pagination creates 3rd page which is coming with empty rows !
I am not sure why some Class ( specially pagination makes so much trouble to users ? ) If i need to pay something ( maybe hidden licence? ) for get away from trouble instead of using simple pagination class without loosing so much time for searching issue on internet , I am ready for it !
I was very mad because of this pagination problem and I was studying the source code of the pagination library and I saw this -- var $uri_segment = 3; The default of the pagination library uses the 3rd uri segment, in your case and in my case we wanted to use the 4th uri segment. To suit our needs change this code:
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config)
TO
$config['base_url'] = site_url('admin/index/page/');
$this->load->database();
$config['total_rows'] = $this->db->count_all('sms');
$config['per_page'] = 20;
$offset = $this->uri->segment(4, 0);
$config['uri_segment'] = 4; // add this line to override the default
$this->pagination->initialize($config)
Kindly post back here if this will solve your problem or if the problem still exists so I can help :)
Nwei this is not in the pagination class documentation. I hope this will be added to the docs because I'm seeing many developers having a hard time with the pagination class.
If you are familiar with how pagination works, then you should be aware that pagination does not add a link tag to the current page. So I'm not sure what you're asking in regards to "pagination class does not create 1 page link".
Also, I don't see where you're offset is being used within the pagination functionality. It seems like you set it but you don't use it. This can cause an incorrect pagination result which I assume is why you get more pagination links than you expect.
$offset = $this->uri->segment(4, 0);
$this->pagination->initialize($config);
One way to change the markup for the "current page" link is 'Customizing the "Current Page" Link'
$config['cur_tag_open'] = '<a href="#">';
The opening tag for the "current" link.
$config['cur_tag_close'] = '</a>';
The closing tag for the "current" link.
The other option is to dive into the pagination class and remove the functionality it has for not adding a link to the current page.
Really, if you're on the current page, it doesn't add any benefit to link to the same page you're already on which I'm assuming is the reason the current page doesn't have a link. If you went to page 2 then the 2 would be disabled. Hope that makes some sense.
No, there no need to pay anything ...CI pagination works perfectly ..you see this library http://codeigniter.com/user_guide/libraries/pagination.html
make sure your $config['total_rows'] = $this->db->count_all('sms'); this code is working correct and providing the correct number of rows and also i would like to suggest use ..$config['uri_segment'] = 3; or $config['uri_segment'] = 4; depend on your urirather than using $offset = $this->uri->segment(4, 0);
Hofefully these few change will work for you....
I was also having the same issue in pagination when using segment number 4. I solved it by using segment number 3. Thats also my problem because I really need to use segment number 4 But Oh well it has bug. I hope this can be solved ASAP. Or if u really need to fix this issue now u can try to fork the source code of pagination class.

Typo3 +TV not rendering content elements

I have installed typo3, templavoila and mapped a template.
Everything works fine, except my content elements. They just don't appear. They did before I installed templavoila and mapped a template.
Also, when using
10 = RECORDS
10 {
tables = tt_content
source = 9
}
it does not give me any output.
even nothing with:
10 = RECORDS
10 {
tables = tt_content
source = 9
conf.tt_content = TEXT
conf.tt_content.value = TEST
}
Does anyone have a clue as to what I might be doing wrong?
You must include the css styled content static template in your TS template.
In your ts page object you need to assign it to the templavoila object.
# Default PAGE object:
page = PAGE
page.typeNum = 0
page.10 = USER
page.10.userFunc = tx_templavoila_pi1->main_page
Probably the page, where tt_content is situated is not visible to regular visitor ?
In this case, following snippet will help.
10 = RECORDS
10.tables = tt_content
10.source = 9
10.dontCheckPid = 1
Finally we got it to work. Don't know what I did wrong, but I guess I learned not to do it again.
I'll put the "solution" here since someone might find it helpful and lose more than a day over this like I did.
Solution:
copy an existing content element in list mode, pasted it on a page via page mode
This was to test if that would do anything. Guess what, everything worked again. Not only the newly copied element but also ALL other test elements created via different ways on different pages and storage folders.
Thank you all for helping and thinking along.

Categories