Magento getUrl function parameter List

Thursday, 21. June 2012

If you have developed on Magento platform before you will have no doubt come across the $this->getUrl(”) function in numerous occassions.

Here is the full list of paramaters that you can use with this function to utilize its full and powerful potential while working with URLs in Magento.

getUrl Parameter List Table

There are several special values that effect the outcome. They all begin with an underscore and are reserved.

Key Type Meaning
_absolute n/a No effect. URLs are always generated as absolute.
_current bool Uses the current module, controller, action and parameters
_direct string Simply append to the base URL, same effect as passing to $routePath. See _store
_escape bool Uses & instead of &
_forced_secure bool Uses the secure domain given in configuration
_fragment string The last part of the URL after a #
_ignore_category bool Only applies to Mage_Catalog_Model_Product_Url::getUrl(). Prevents category rewrite from being used.
_nosid bool Prevents a SID query parameter being used when referencing another store
_query string or array If an array it is converted into a string like ?key=value&key=value which will become the $_GET variable.
_secure bool Uses the secure domain if allowed in configuration
_store int or string Either the numeric store ID or textual store code. It will use the correct domain as the base URL.
_store_to_url bool Adds ___store to the query parameters. Useful for targetting a store that doesn’t have an unique domain.
_type string link is the default. direct_link is useful for bypassing the ‘store code in URLs’ feature. js, media and skin append the domain (and possibly store code) with the relevant directory.
_use_rewrite bool Looks up the module/controller/action/parameters in the database for a search engine friendly equivalent.

getUrl function examples

**Current Page**
Full path is preserved. Fragment and queries are stripped.

Mage::getUrl('', array(
    '_current' => true,
    '_use_rewrite' => true
));

**Current Page, Secured, For Another Store**
Session ID may well be added automatically to solve the cookie problem.

Mage::getUrl('', array(
    '_current' => true,
    '_use_rewrite' => true,
    '_secure' => true,
    '_store' => 2,
    '_store_to_url' => true
));

**Static Page On Main Store**
Session ID is stripped, the static will not be using it. A type of direct_link means a store code is not inserted.

Mage::getUrl('example.html', array(
    '_nosid' => true,
    '_store' => 'default',
    '_type' => 'direct_link'
));

Enjoy!!

Leave a Reply

You must be logged in to post a comment.