Changes to lnk() helper to provide way to add base classes to link. Example usage in users_show -view where link now includes "button medium" classes

This commit is contained in:
Ismo Vuorinen
2013-07-18 13:03:41 +03:00
parent 61f5693474
commit 1b8e388508
2 changed files with 12 additions and 8 deletions

View File

@@ -3,16 +3,17 @@
/**
* lnk helps return anchor tag with class when current_url() is site_url($match)
*
* @param string $url Your link inside the application, not for outside links
* @param string $text Link text
* @param string $match What url to match against, use like $url
* @param string $class What class should be added if urls match
* @param string $url Your link inside the application, not for outside links
* @param string $text Link text
* @param string $baseclass What classes should be included
* @param string $match What url to match against, use like $url
* @param string $class What class should be added if urls match
*
* @author Ismo Vuorinen <ismo.vuorinen@tampere.fi>
*
* @return string Formatted anchor tag with everything needed
*/
function lnk($url = null, $text = null, $match = null, $class = ' active')
function lnk($url = null, $text = null, $baseclass = '', $match = null, $class = ' active')
{
// $url should be "controller/action", no need to give full url
$url = site_url($url);
@@ -26,9 +27,12 @@ function lnk($url = null, $text = null, $match = null, $class = ' active')
// Return correctly formatted link
if ($url == $match) {
return '<a class="' . $class . '" href="' . $url . '">' . $text . '</a>';
return '<a class="' . $baseclass . $class . '" href="' . $url . '">' . $text . '</a>';
} else {
return '<a href="'. $url .'">' . $text . '</a>';
if (! empty($baseclass)) {
$baseclass = 'class="' . $baseclass . '" ';
}
return '<a ' . $baseclass . 'href="'. $url .'">' . $text . '</a>';
}
}

View File

@@ -25,7 +25,7 @@ if ($user->can_modusers == "no") {
} elseif (empty($userdata) || ! is_object($userdata)) {
?>
<h2>Käyttäjää tunnisteella #<?php echo $userid; ?> ei löydetty</h2>
<?php echo lnk("yllapito/users", "Takaisin"); ?>
<?php echo lnk("yllapito/users", "Takaisin", 'button medium'); ?>
<?php
} else {