I am upgrading my site from some old spaghetti coding to some nice, clean custom MVC structure (and having fun learning in the process).
On my page to display blog listings, I had a function that would help my dynamically build HREF's for the a links - to keep track of applied filters via $_GET...hard to explain...but here it is:
/* APPLY BROWSE CONTROLS / FILTERS
| this function reads current $_GET values for controlling the feed filters,
| and replaces the $value with the desired new $value
*/
function browse_controls($key,$value=null,$ret='url') {
// find current control settings
$browse_controls = array();
if(array_key_exists('browse',$_GET)) { $browse_controls['browse'] = $_GET['browse']; }
if(array_key_exists('display',$_GET)) { $browse_controls['display'] = $_GET['display']; }
if(array_key_exists('q',$_GET)) { $browse_controls['q'] = $_GET['q']; }
// replace desired setting
if($value) {
$browse_controls[$key] = $value;
}else{
unset($browse_controls[$key]);
}
// build url
$url = ABS_DOMAIN . 'sale/';
if(!empty($_GET['cat'])) { $url .= $_GET['cat'] . '/';}
if(!empty($_GET['sub'])) { $url .= $_GET['sub'] . '/';}
$url .= '?' . http_build_query($browse_controls);
return $url;
}
I could call this query by simply:
<a href='<?php echo browse_controls('browse',$prev_page); ?>' class="crumb">Previous Page</a>
How can I achieve that same with MVC structure and full separation of presentation and logic. Are functions allowed in my template?
Help!