We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

what's last argument in Phalcon\Mvc\Url::get() for?

What is the goal of the last $local argument in Phalcon\Mvc\Url::get()?


public string get ([string|array $uri], [unknown $args], [bool|null $local])

It is not explained in the docs. I have tried to generarte URL with this argument set to true and false but haven't found any difference.

edited Aug '14

I think this argument is true by default, this is to indicate if the url is local (relative) or external (absolute)

$URL = new Phalcon\Mvc\Url;
// If you are on https://example.com/XX/
echo $URL->get('google.com', array(), false); //   CC/AA .. local relative to the current URL, https://example.com/XX/google.com
echo $URL->get('google.com', array(), true); //   /CC/AA .. local absolute to the current Domain, https://example.com/google.com
// Adding HTTP://
echo $URL->get('https://google.com', array(), false); //  external absolute URL, https://google.com
echo $URL->get('https://google.com', array(), true); //   local relative to the current URL https://example.com/XX/CC/AA/https://google.com
// So from the results you can see which links is true or not


26.3k

@hishamaborob could you explain it a little more? I don't get it yet. What you mean by "work"?

Why sb would produce a link like "google.com" with URL component?

I have tried to generate some URLs with this 3rd parameter set to true and false and there is no difference in what is produced.

Sorry there was some mistakes, I fixed it and made it more clear I hope



26.3k

Last line of your code is:


echo $URL->get('https://google.com', array(), true); // https://example.com/XX/CC/AA/https://google.com

How the URL component is capable to add these letters CC/AA between https://example.com/XX and https://google.com? Where the string CC/AA is defined?



26.3k

I have tried your code. I have changed all echo to var_dump:


$URL = new \Phalcon\Mvc\Url;
var_dump($URL->get('google.com', array(), false));
var_dump($URL->get('google.com', array(), true));
var_dump($URL->get('https://google.com', array(), false));
var_dump($URL->get('https://google.com', array(), true));

What I have received is:


string 'google.com' (length=10)
string '/public/google.com' (length=18)
string 'https://google.com' (length=17)
string '/public/https://google.com' (length=25)