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

Cannot getBaseUri() correctly.

My phalcon app is in folder /_test-php-framework/phalcon/ And i'm already set application->baseUri = /_test-php-framework/phalcon/

In config/services.php i have this code running

$di = new FactoryDefault();

/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use ($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);

    return $url;
});

Everythingelse works find except when i call to getBaseUri().

$url = new Phalcon\Mvc\Url();
echo $url->getBaseUri()."<br>\n";

The result should be /_test-php-framework/phalcon/ but it becomes /public/

How to get its value correctly?

Hello I tried "url.getBaseUri()" and the output is "/_whateveryousay/" (in my case). It worked



6.2k
edited Mar '15

Hello I tried "url.getBaseUri()" and the output is "/_whateveryousay/" (in my case). It worked

Are you sure that is php code? url.getBaseUri()?



6.2k
Accepted
answer

I use it in controller (mvc). So, i changed to $this->uri->getBaseUri() and it work!

This works in the view's too.

I use it in controller (mvc). So, i changed to $this->uri->getBaseUri() and it work!