|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
darren.hoo Smarty n00b
Joined: 01 Mar 2005 Posts: 2 Location: Beijing,China
|
Posted: Wed Mar 02, 2005 6:34 am Post subject: setting custom parameters in SmartyPaginate! |
|
|
As is said in SmartyPaginate doc,
Code: | SmartyPaginate:setUrl() set the URL used in the paginator links to navigate from page. |
so if I want to setting custom parameters in SmartyPaginate,first I have retain it in some session variable,every time I invoke smartypaginate I have to setup the parameters and pass it to smarty using setUrl(),and I have aslo have to watch if the parameter changes I have to reset paginator.I find it a hardwork if I have many parameter to pass.
I changed SmartyValidate.class.php to suit my needs ,It works but I don't know whether it's right.
Code: |
function _getNextPageItem($id = 'default') {
$_next_item = $_SESSION['SmartyPaginate'][$id]['current_item'] + $_SESSION['SmartyPaginate'][$id]['item_limit'];
return ($_next_item <= $_SESSION['SmartyPaginate'][$id]['item_total']) ? $_next_item : false;
}
/**
* set custom url parameters
*
* @param string $id the pagination id
*/
function setParam($params,$id = 'default'){
if(!isset( $_SESSION['SmartyPaginate'][$id]['param']) || $_SESSION['SmartyPaginate'][$id]['param']!=$params){
SmartyPaginate::reset($id);//reset the paginator in case the parameter changes
}
$_SESSION['SmartyPaginate'][$id]['param'] = &$params;
}
/**
* get custom url parameters
*
* @param string $id the pagination id
*/
function getParam($id = 'default'){
foreach( $_SESSION['SmartyPaginate'][$id]['param'] as $key => $param){
$params .= $key.'='.$param.'&' ;
}
return $params;
}
|
and in function.paginate_middle.php I changed it as follows:
Code: |
if($_item != $_curr_item) {
$_this_url = $_url;
$_this_url .= (strpos($_url, '?') === false) ? '?' : '&';
$_this_url .= SmartyPaginate::getParam($_id);
$_this_url .= SmartyPaginate::getUrlVar($_id) . '=' . $_item;
$_ret .= '<a href="' . str_replace('&', '&', $_this_url) . '">'
. $_text . '</a>';
}
|
and I used it like this:
Code: |
$params = array();
if(isset($_GET['subjectId']) && is_numeric($_GET['subjectId'])){
$subjectId = $_GET['subjectId'];
$params['subjectId'] = &$subjectId;
}else{
$subjectId=-1;
}
if(isset($_GET['sourceId']) && is_numeric($_GET['sourceId'])){
$sourceId = $_GET['sourceId'];
$params['sourceId'] = &$sourceId;
}else{
$sourceId=-1;
}
SmartyPaginate::connect('myasklist');
SmartyPaginate::setLimit(10,'myasklist');
SmartyPaginate::setParam($params,'myasklist');
|
finally I will get url like:
/my/qna/newsolvelist/?subjectId=4&sourceId=2&next=51
I haven't test it as to code performance.
any suggestions? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 02, 2005 3:01 pm Post subject: |
|
|
So it looks like you want the ability to add parameters to the pagination URL, but those parameters are only good for the current invocation? Or they persist? |
|
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
|