ExtBase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / View / Helper / URIHelper.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A URI/Link Helper
27 *
28 * @package TYPO3
29 * @subpackage extbase
30 * @version $ID:$
31 */
32 class Tx_ExtBase_View_Helper_URIHelper extends Tx_ExtBase_View_Helper_AbstractHelper {
33
34 /**
35 * @var Tx_ExtBase_Web_Routing_RouterInterface
36 */
37 protected $router;
38
39 /**
40 * Creates a link by making use of the Routers reverse routing mechanism.
41 *
42 * @param string $label Inner HTML of the generated link. Label is htmlspecialchared by default
43 * @param string $actionName Name of the action to be called
44 * @param array $arguments Additional arguments
45 * @param string $controllerName Name of the target controller. If not set, current controller is used
46 * @param string $extensionName Name of the target extension. If not set, current extension is used
47 * @param string $subextensionName Name of the target subextension. If not set, current subextension is used
48 * @param array $options Further options
49 * @return string the HTML code for the generated link
50 * @see UIRFor()
51 */
52 public function linkTo($label, $actionName, $arguments = array(), $controllerName = NULL, $extensionName = NULL) {
53 $link = '<a href="' . $this->URIFor($actionName, $arguments, $controllerName, $extensionName) . '">' . htmlspecialchars($label) . '</a>';
54 return $link;
55 }
56
57 /**
58 * Creates an URI by making use of the Routers reverse routing mechanism.
59 *
60 * @param string $actionName Name of the action to be called
61 * @param array $arguments Additional arguments
62 * @param string $controllerName Name of the target controller. If not set, current controller is used
63 * @param string $extensionName Name of the target extension. If not set, current extension is used
64 * @param array $options Further options
65 * @return string the HTML code for the generated link
66 */
67 public function URIFor($actionName, $arguments = array(), $controllerName = NULL, $extensionName = NULL) {
68 $routeValues = $arguments;
69 $routeValues['@action'] = $actionName;
70 $routeValues['@controller'] = ($controllerName === NULL) ? $this->request->getControllerName() : $controllerName;
71 $routeValues['@extension'] = ($extensionName === NULL) ? $this->request->getExtensionName() : $extensionName;
72
73 $URIString = $this->router->resolve($routeValues);
74 return $URIString;
75 }
76 }
77
78 ?>