1

I'm new to phalcon and I need assistance because i cannot find a way to get full path url (and add it in an email message) such as : "http://phalcon.mydomain.com/auth/confirmRegistration"

the most i could get is "/auth/confirmRegistration"

using $this->url->getStatic('auth/confirmRegistration')

there might be a build in function but i could not discover it, or maybe i should put the 'http://phalcon.mydomain.com' part in a global variable ??

thank you in advance

humugus
  • 13
  • 1
  • 1
  • 4

2 Answers2

9

Here's a simple way to get the url of the current page in Phalcon:

echo $this->router->getRewriteUri();
hanmari
  • 1,384
  • 12
  • 19
2

You could do two things. Per documentation you could set the full domain url:

<?php

$url = new Phalcon\Mvc\Url();

//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('http://my.domain.com/my-app/');

Or you could simply use HTTP_HOST / SERVER_NAME to get the host name and append the rest of it, e.g:

echo 'http://' . $_SERVER['SERVER_NAME'] . '/auth/confirmRegistration';
Community
  • 1
  • 1
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72
  • thank you for your reply, both of your suggestions work fine, but i actually use (so far) another option : define('BASE_URL', 'http://phalcon.mydomain.com'); by your experience, would you suggest one of them for a particular reason ? – humugus Feb 19 '14 at 08:08
  • Your BASE_URL is already defined in $_SERVER['SERVER_NAME'], unless you want to use a different value for that. Also, this value is likely to change between your dev and production, so you'd need to keep an eye on it. Apart from that this solution is perfectly fine. I would not use `$url->setBaseUri('http://my.domain.com/my-app/')` because it would affect all other generated urls and I personally wouldn't want that. – Ian Bytchek Feb 20 '14 at 11:06