add query parameters to an existing url string

echo Mage::getUrl('',
    array(
        '_direct' => Mage::getModel('core/url_rewrite')->loadByIdPath('category/1')->getRequestPath(),
        '_query' => array('param1' => 'myparam1','param2' => 'myparam2')
    )
);

I don't think there is a 'built in' way to achieve this.
The method Mage_Catalog_Model_Url::getUrl() does not accept any parameters. You can override the method, but unless you need something like this for all categories I don't see a point on doing it.
I think the cheapest way is to add the parameters directly.

$params = array('param1' => 'myparam1','param2' => 'myparam2');
$categoryUrl = Mage::getModel('catalog/category')->load(1)->getUrl();
$urlParams = array();
foreach ($params as $name=>$value){
    $urlParams[] = $name.'='.urlencode($value);
}
$urlParams = implode('&', $urlParams);
if ($urlParams){
    $glue = '?';
    if (strpos($categoryUrl, $glue) !== false){//this should never happen - but just in case
        $glue = '&';
    }
    $categoryUrl .= $glue.$urlParams;
}

You can make this a method in a helper to avoid writing the code each time you need it.

For any other url that you construct through Mage::getUrl() you can pass query params like this:

$url = Mage::getUrl('module/controller/action', array('param1'=>'val1', '_query'=>array('p1'=>'v1', 'p2'=>'v2')));

the code above will generate the following:

http://mysite.com/module/controller/action/param1/val1/?p1=v1&p2=v2


You can use core/url helper:

$params = array('param1' => 'myparam1', 'param2' => 'myparam2');
$newCategoryUrl = Mage::helper('core/url')->addRequestParam($categoryUrl, $params);

Tags:

Url