0

When extension is installed first time, it returns proper url with domain included. But if I try to run extension setup script again (by deleting row in core_resource table) it return just "/". And for Mage::getBaseUrl() return "index.php".

Inside mysql4-upgrade-1.1.3-1.1.4.php:

$installer = $this;
$mediaPath = Mage::getBaseUrl('media');
var_dump($mediaPath());
var_dump(Mage::getBaseUrl()); exit;

Am I forgetting something? Is there any other way to get media url with domain included?

2 Answers 2

1

The reason for this is because when you call Mage::getBaseUrl('media') it loads a store. If you are in update mode, then it will load some default information about a store and not the full store. See Mage_Core_Model_App

protected function _getDefaultStore()
{
    if (empty($this->_store)) {
        $this->_store = Mage::getModel('core/store')
            ->setId(self::DISTRO_STORE_ID)
            ->setCode(self::DISTRO_STORE_CODE);
    }
    return $this->_store;
}

But if you use this in a data set-up script under the folder data rather than sql then you will be able to load this information.

Basically the resource updates (files under sql folder) happen before the store has been initialised and the data updates happen after, so the store has been fully loaded.

0

You can get media url using this code Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

For further information please follow this link http://universalcoder.wordpress.com/2014/03/04/magento-get-base-media-skin-js-url/

3
  • This also return just '/'. It seems I will need to use $_SERVER['HTTP_HOST'].
    – JohnyFree
    Commented Apr 14, 2014 at 14:44
  • I dont think it is the best way. Can you tell me in which file you are trying to call the media URL ?
    – Dexter
    Commented Apr 15, 2014 at 5:30
  • mysql4-upgrade-1.1.3-1.1.4.php
    – JohnyFree
    Commented Apr 15, 2014 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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