I'm passing a url string variable from a controller to a phtml file where i'd like to then display it as a hyperlink.

unfortunately, magento seems to prefix the variable data with the controller's url.

so a variable that's passed like this www.something.com is converted to www.mydomain.com/my_controller/www.something.com when calling this in the phtml to create a hyperlink.

 <?php echo "<a href='" . $this->myVar . "'>html link in php</a><p>";?>

if i make a simple call this, it displays the text correctly:

 <?php echo $this->myVar?>

i've tried calling this to strip the added url:

$newURL = str_replace("www.mydomain.com/my_controller/", "", $this->myVar, $count);

but php doesn't seem to find the substring and count = 0.

seems like magento is adding the controller's url automatically, which is not what i need.

this is how i'm rendering the page.


    $block = $this->getLayout()->createBlock(
        array('template' => 'NamespaceName_ModuleName/links.phtml')
    ->setData('var', 'www.something.com');


Any ideas?


This is URL 101. You have not specified http:// in front of the link, so the browser tries to append it to the current location.

  • html 101...figured it was something beyond simple. in my defense, i'm not a web guy. thanks for being gentle! – user3348950 Jun 3 '15 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.