simple-php-router
simple-php-router copied to clipboard
Can't get full url instead of root/article/33
I'm trying to make it show full url (for example: https://site.com/article/33) instead of root/article/33 but the Router::getUrl() returns an object instead of string and you know...
$out = url('search',null, ['q' => 'mitsubishi']);
dump($out);
How can I do that way simple? https://site.com/article/33
Hi.
$out = url('search',null, ['q' => 'mitsubishi'])->getAbsoluteUrl();
dump($out);
How about this?
The point this time is to use getAbsoluteUrl().
Hey, can you explain your goal a little bit more? I can recieve the current url using:
\Pecee\SimpleRouter\SimpleRouter::get('/article/33', function(){
var_dump(\Pecee\SimpleRouter\SimpleRouter::request()->getUrl()->getAbsoluteUrl());
});
You can also name the routes and recieve the url using the following:
\Pecee\SimpleRouter\SimpleRouter::get('/article/{article}', function(){
var_dump(\Pecee\SimpleRouter\SimpleRouter::getUrl('article-url', array(
'article' => 33
))->getAbsoluteUrl());
})->name('article-url');
~ Marius