如何在magento中连接url中的变量

I'm trying to add Variable in URL in magento. Here is my link:

<?php echo Mage::helper("html")->getUrl("admin/index/test/".$testId); ?>

If i add / at the end of profile then url not concatenate with testId. But if concatenate testId without adding / at the end of profile then it's not concatenate variable id. here is link

<?php echo Mage::helper("html")->getUrl("admin/index/test".$testId); ?>

Can anyone describe me, what i'm missing?

There are a few mistakes:

  • the first parameter to getUrl must be a route in the form router/controller/action. Additional parameters can be added with the second parameter
  • the router for the admin URL is called adminhtml. Magento distinguishs between front name (the first part of the URL) and router (the internal value), which makes it possible to have a custom admin URL. This is configured in app/code/core/Mage/Adminhtml/etc/config.xml:

    <routers>
        <adminhtml>
            <use>admin</use>
            <args>
                <module>Mage_Adminhtml</module>
                <frontName>admin</frontName>
            </args>
        </adminhtml>
    </routers>
    
  • The last part(s) of a route can be ommitted in the URL if they are "index", so for the URL /admin, the route is adminhtml/index/index. But as soon as you want to add parameters, all parts are required, to distinguish the parameters from controller and action. It looks like you want to add the parameter test=$testId to the existing route adminhtml/index/index, which redirects to the configured start page, by default adminhtml/dashboard/index, or to the login page if you are not logged in.

  • For admin URLs, you need to use the adminhtml helper (or the adminhtml/url model)

Conclusion

To get the URL admin/index/index/test/$testId, the first parameter must be adminhtml/index/index and the second parameter ['test' => $testId]

echo Mage::helper("adminhtml")->getUrl("adminhtml/index/index", ['test' => $testId]); 

Alternative

If you want to build the URL with GET parameters in the form admin?test=$testId, you can use the _query parameter:

echo Mage::helper("adminhtml")->getUrl("adminhtml/index/index",
    ['_query' => ['test' => $testId]]); 

Try this

echo Mage::helper("adminhtml")->getUrl("adminhtml/index/index",array('test'=>$testId));