 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
ucntkilme Smarty Regular
Joined: 03 Sep 2007 Posts: 84
|
Posted: Fri Jul 09, 2010 7:27 pm Post subject: SmartyPaginate and Ajax Solved |
|
|
Me, like many others are using AJAX now days. Until now, I have not found a way to make SmartyPaginate allow the use of the onclick command to use AJAX with it.
I have solved this issue, and thought anyone else might be interested in seeing how i've done it.
First off, I had to go into each of the SmartyPaginate files...
in SmartyPaginate.class file I added the following functions:
| Code: |
/**
* set the ajax variable ie. 1 or 0
*
*/
function setAjax($avar, $id='default') {
$_SESSION['SmartyPaginate'][$id]['avar'] = $avar;
}
/**
* get the ajax variable
*/
function getAjax($id = 'default') {
return $_SESSION['SmartyPaginate'][$id]['avar'];
}
|
Then I had to go into the SmartyPaginate function files for First, Last, Middle, Prev and Next
in the First, Last, Prev and Next files the additions were the exact same.
@ line 64 I added in:
| Code: |
$_ajax = SmartyPaginate::getAjax($_id);
|
at line 75 I replaced:
| Code: |
return '<a href="' . str_replace('&','&', $_url) . '"' . $_attrs . '>' . $_text . '</a>';
|
with:
| Code: |
if($_ajax == '1') {
return $_show ? '<a href="index.php" onClick="' . str_replace('&','&', $_url) . '\'); return false;"' . $_attrs . '>' . $_text . '</a>' : '';
} else {
return $_show ? '<a href="' . str_replace('&','&', $_url) . '"' . $_attrs . '>' . $_text . '</a>' : '';
}
|
That is all the edits needed in the First, Last, Prev and Next files in order to get them to use Ajax.
The middle was a little bit tricker.
@ line 90 I added:
| Code: |
$_ajax = SmartyPaginate::getAjax($_id);
|
at line 120 I replaced:
| Code: |
$_ret .= $_link_prefix . '<a href="' . str_replace('&', '&', $_this_url) . '"' . $_attrs . '>' . $_text . '</a>' . $_link_suffix;
|
with:
| Code: |
if ($_ajax == '1') {
$_ret .= $_link_prefix . '<a href="index.php" onClick="' . str_replace('&','&', $_this_url) . '\'); return false;"' .$_attrs . '>' . $_text . '</a>' . $_link_suffix;
} else {
$_ret .= $_link_prefix . '<a href="' . str_replace('&', '&', $_this_url) . '"' . $_attrs . '>' . $_text . '</a>' . $_link_suffix;
}
|
The last thing we have to do is set it all up in our PHP file when we're setting up all of the variables for the Pagination system itself.. and this is done like so:
| Code: |
SmartyPaginate::setAjax(1);
SmartyPaginate::setURL("changeNavigation('index.php?pg=users&act=employs");
|
Notice that on the changeNavigation function that I wrote, I didn't include the ending ')
The reasoning behind this is, the pagination system needs to be able to add on to the URL and if we add that in the setURL, it will not work correctly.
Anyway give it a go, let me know what you think.. and like I said anything that can maybe done to speed up the middle portion, I'd be interested in hearing about that and if Mohrt decides to add in this ajax functionality cool -- just give me credit  |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|