Phalcon\Url is the component responsible of generate URLs in a Phalcon application. It’s capable of produce independent URLs based on routes.
Setting a base URI
Depending of which directory of your document root your application is installed, it may have a base URI or not.
For example, if your document root is /var/www/htdocs and your application is installed in /var/www/htdocs/invo then your baseUri will be /invo/. If you are using a VirtualHost or your application is installed on the document root, then your baseUri is /. Execute the following code to know the base URI detected by Phalcon:
By default, Phalcon automatically may detect your baseUri, but if you want to increase the performance of your application is recommended setting up it manually:
<?phpusePhalcon\Url;$url=newUrl();// Setting a relative base URI$url->setBaseUri('/invo/');// Setting a full domain as base URI$url->setBaseUri('//my.domain.com/');// Setting a full domain as base URI$url->setBaseUri('https://my.domain.com/my-app/');
Usually, this component must be registered in the Dependency Injector container, so you can set up it there: