simple-php-router icon indicating copy to clipboard operation
simple-php-router copied to clipboard

Can't get full url instead of root/article/33

Open amirandev opened this issue 3 years ago • 2 comments

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

amirandev avatar Jun 14 '22 18:06 amirandev

Hi.

$out = url('search',null, ['q' => 'mitsubishi'])->getAbsoluteUrl();
dump($out);

How about this? The point this time is to use getAbsoluteUrl().

riku22 avatar Jun 21 '22 04:06 riku22

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

DeveloperMarius avatar Nov 10 '22 13:11 DeveloperMarius