Working with URLs – Nette\Http\Url
Class Nette\Http\Url encapsulates any URLs according to RFC 3986 and allows easy manipulation with their parts.
The following scheme covers individual parts of URL:
scheme user password host port basePath relativeUrl
| | | | | | |
/--\ /--\ /------\ /-------\ /--\/--\/----------------------------\
http://john:x0y17575@nette.org:8042/en/manual.php?name=param#fragment
\__________________________/\____________/^\________/^\______/
| | | |
authority path query fragment
Usage is then very intuitive:
use Nette\Http\Url;
$url = new Url('http://nette.org/en/documentation?action=history#footer');
echo $url->absoluteUrl; // or directly echo $url; returns full URL
echo $url->scheme; // http
echo $url->authority; // nette.org
echo $url->hostUrl; // http://nette.org
echo $url->path; // /en/documentation
echo $url->query; // action=history
echo $url->fragment; // footer
In addition to http URL scheme, it's possible to use others,
for example https, file or ftp.
Parts of an URL can of course be changed.
$url = new Url('http://nette.org/en/documentation?action=history#footer');
$url->path = '/';
$url->appendQuery('page=1');
echo $url; // http://nette.org/?action=history&page=1#footer
The canonicalize() method converts URL to its canonical form.
Nette\Http\UrlScript
Class UrlScript is a
descendant of Url. It indicates which part of URL is a path to
currently running script. It is used inside Nette\Http\Request class.
http://nette.org/admin/script.php/pathinfo/?name=param#fragment
\_______________/\________/
| |
scriptPath pathInfo
