forked from slimphp/Slim-Views
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.urlFor.php
More file actions
42 lines (36 loc) · 1.27 KB
/
function.urlFor.php
File metadata and controls
42 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Smarty plugin
* -------------------------------------------------------------
* File: function.urlFor.php
* Type: function
* Name: urlFor
* Purpose: outputs url for a function with the defined name method
* @version 0.1.3
* @package SlimViews
* -------------------------------------------------------------
*/
function smarty_function_urlFor($params, $template)
{
$name = isset($params['name']) ? $params['name'] : '';
$appName = isset($params['appname']) ? $params['appname'] : 'default';
$url = \Slim\Slim::getInstance($appName)->urlFor($name);
if (isset($params['options'])) {
switch (gettype($params['options'])) {
case 'array':
$opts = $params['options'];
break;
case 'string':
$options = explode('|', $params['options']);
foreach ($options as $option) {
list($key, $value) = explode('.', $option);
$opts[$key] = $value;
}
break;
default:
throw new \Exception('Options parameter is of unknown type, provide either string or array');
}
$url = \Slim\Slim::getInstance($appName)->urlFor($name, $opts);
}
return $url;
}