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

wrong generated links

I am testing localhost/whitespace/book24

I am having issue, while creating the links i.e. the links are generating as localhost/assests/css/

I have set url in my service.php

$config->application->baseUri = '/whitespace/book24/';

$di->set('url', function () use ($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->application->baseUri);
    return $url;
}, true);

css links in volt file.

<link href="/assests/css/style.css">

can anyone helps ?

//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/');

echo $url->get("controller/action");

https://stackoverflow.com/questions/21856287/how-to-get-full-path-url-in-phalconphp



43.9k

Hi,

for loading css files:

use tag service: https://docs.phalcon.io/en/latest/reference/tags.html#stylesheets

or much better if you have a bunch of static assets like css and js: phalcon's asset manager: https://docs.phalcon.io/en/latest/reference/assets.html

Hey, Thanks for telling about assets manager. but the problem of the link is all over the app. that is if i define anchor tag like this <a href="/contact/index"> it goes to localhost/contact/index and not localhost/whitespace/book24/contact/index.



43.9k
Accepted
answer

hi,

use tag helper (for loading css, but also for creating links: https://docs.phalcon.io/en/latest/reference/tags.html#generating-links)

Hey, Thanks for telling about assets manager. but the problem of the link is all over the app. that is if i define anchor tag like this <a href="/contact/index"> it goes to localhost/contact/index and not localhost/whitespace/book24/contact/index.

That's normal behaviour of HTML relative links (anchors). Try to ommit the leading slash / and see the difference.

Just follow what others told you here already if you want to do it right.