Gernerate custom urls within Magento

后端 未结 3 795
鱼传尺愫
鱼传尺愫 2020-12-13 22:21

I am currently looking at trying to generate custom urls/routing using magento, currently I have set a default route in config.xml within the local module.

&         


        
3条回答
  •  不思量自难忘°
    2020-12-13 22:40

    The way to do this is with an URL rewrite. In fact, the suffix config you found is probably used by Mage_Catalog to create it's sets of rewrites. I'm approaching this particular feature for the first time so this snippet should be taken with a pinch of salt...

    // Creating a rewrite
    /* @var $rewrite Mage_Core_Model_Url_Rewrite */
    $rewrite = Mage::getModel('core/url_rewrite');
    $rewrite->setStoreId($store_id)
            ->setIdPath('portfolios/'.$url_key)
            ->setRequestPath('portfolios/'.$url_key.'.html')
            ->setTargetPath('portfolios/index/action/id/'.$url_key)
            ->setIsSystem(true)
            ->save();
    

    A new rewrite is needed for each possible path.

    Edit; I've added a setIdPath because it might be necessary.

提交回复
热议问题