Skip to content

Commit

Permalink
Merge pull request #16 from ha1t/add_url_helper
Browse files Browse the repository at this point in the history
Add url helper
  • Loading branch information
tsukimiya committed Dec 16, 2014
2 parents d14327b + d96064f commit 7cc6998
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion app/helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,27 @@ function eh($string)
return;
}
echo htmlspecialchars($string, ENT_QUOTES);
}
}

function url($url = '', $params = array())
{
$query = http_build_query($params);
if (strlen($query) > 0) {
$query = '?' . $query;
}
if ($url === '') {
$url = substr($_SERVER['REQUEST_URI'], strlen(APP_BASE_PATH));
$url = APP_URL . $url;
} elseif ($url === '/') {
$url = APP_URL . $query;
} elseif (strpos($url, 'http') === 0) {
$url = $url . $query;
} elseif (strpos($url, '#') === 0) {
$url = $url;
} elseif (strpos($url, '?') === 0) {
$url = $url;
} else {
$url = APP_BASE_PATH . $url . $query;
}
return $url;
}
4 changes: 2 additions & 2 deletions app/views/layouts/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title><?php eh($title)?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo url('bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
Expand All @@ -22,6 +22,6 @@
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo url('bootstrap/js/bootstrap.min.js') ?>"></script>
</body>
</html>

0 comments on commit 7cc6998

Please sign in to comment.