xp-framework/rfc — Issue #28: Add a method forwardTo() to XMLScriptletResponse
Author: thekid
Created: 2011-10-17 15:40:58+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
A new method forwardTo() will be added to the XMLScriptletResponse class.
This method will redirect relatively to the base URI.

Rationale
====
A redirect (HTTP statuscodes 301 / 302 with Location header) needs an
absolute URI to be RFC-conform. Assembling this URI is tedious and
developers tend to end up writing $response->redirect('../foo/bar'),
which works fine because browsers are quite relaxed on this issue.

Functionality
====

Current functionality
----

```php
getURI();
$sessionId= $request->session ? $request->session->getId() : NULL;
$response->sendRedirect(sprintf(
'%s://%s/xml/%s.%s%s/%s%s%s',
$uri['scheme'],
$uri['host'],
$request->getProduct(),
$request->getLanguage(),
empty($sessionId) ? '' : '.psessionid='.$sessionId,
$stateName,
empty($query) ? '' : '?'.$query,
empty($fraction) ? '' : '#'.$fraction
));
?>
```

New functionality
----

```php
forwardTo($stateName);

// Also attach a query string and a fraction, e.g. {
// stateName: 'news/view'
// query: '5'
// fraction: 'extended'
// }
$response->forwardTo($stateName, $query, $fraction);
?>
```

Note that neither the query argument nor the fraction argument contain
the separators ("?" for query, "#" for fraction)!

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
- New method in XMLScriptletResponse

Related documents
====
- Patch implementing this RFC
http://xp-framework.net/downloads/rfc0028.diff