3

Hi want to build the query string in magento. I tried

<?php 
echo $this->getUrl("catalog/category/view",
  array(
    "_use_rewrite"=>false,
    "category"=>$_category->getId(),
    "product"=>$_product->getId()
  )
);
?>

i want the url: http://www.localhost.com/hungermunch/fujigrill/catalog/category/view?category=11&product=1 but im getting

http://www.localhost.com/hungermunch/fujigrill/catalog/category/view/category/11/product/1/

how can i get the required url . Is it possible

4
  • but why you use rewrite just add what you want after category url Commented Jul 5, 2012 at 10:55
  • I want to send the data throug ajax so i think it will be easy for me to do that way.If there is another way for that Commented Jul 9, 2012 at 6:54
  • use something like $this->getUrl("catalog/category/view")?product=pid&category=cid Commented Jul 9, 2012 at 10:11
  • hi samit rimal i have vote up all ur question and answers ur reputation is now increase from 15 to 57..now happy.. Commented Jan 2, 2013 at 8:47

2 Answers 2

4

You can also append url querystring params in Magento like this:

$params = array(
    '_query' => array(
        'category' => $_category->getId(),
        'product'  => $_product->getId(),
    )
);

echo Mage::getUrl('catalog/category/view', $params);

Here's a reference for the getUrl() method:

http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to add on a query string to the end you could use this method:

$this->getUrl("catalog/category/view") . "?" .
http_build_query(
    "category" => $_category->getId(),
    "product"  => $_product->getId()
);

Although I see no reason not to use your first method, and then get the values from Magento as you need them, for example inside a controller you can do this:

$productId = $this->getRequest()->getParam('product');
$categoryId = $this->getRequest()->getParam('category');

Magento will then get those values for you from the url generated by your code.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.