Magento URL Redirect from Controller
https://www.apptha.com/blog/magento-url-redirect-from-controller/_redirect()This function is the key which helps to redirect between Magento modules.Example:<?php// $this->_redi
https://www.apptha.com/blog/magento-url-redirect-from-controller/
_redirect()
This function is the key which helps to redirect between Magento modules.
Example:
<?php // $this->_redirect('module/controller/action'); $this->_redirect('customer/account/login'); ?>
We can redirect within our current controller by specifying ‘*’. Here is the example,
<?php $this->_redirect('*/*/success'); ?>
In the above mentioned code, the first ‘*’ specifies current ‘Module’, the second ‘*’ specifies current ‘Controller‘ and ‘success’ refers to the ‘Action‘. But, this _redirect() function will help to redirect within magento stores only (module/controller/action) which means there is no possibility to redirect requests to an external URL(like http://contus.com).
Now, let us look at the method to redirect requests to external URLs
_redirectUrl()
This is the key function which helps to redirect our action to external URL outside Magento base. Using this function, we can either use Magento’s method or can pass full path like http://contus.com to redirect.
Here is the example,
<?php $this->_redirectUrl('customer/account/login'); // or $this->_redirectUrl('http://contus.com'); ?>
Note: Try out the codes mentioned below if both of the previously mentioned suggestions don’t work.
<?php Mage::app()->getResponse()->setRedirect($url)->sendResponse(); // or Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse(); ?>
Other useful codes that would help:
For creating a secured URL:
Mage::getUrl('customer/account/login', array('_secure' => true));
For passing parameters with the URL:
Mage::getUrl('customer/account/login', array('_secure' => true, 'parameter_name'=>'value', 'param2'=>'val'));
For getting parameters from the URL:
we can get the parameters value using
$this->getRequest()->getParam('parameter_name');
Raise your queries as questions in our forum to get clarifications from certified Magento developers Support Forum.
Let us know your feedback in the comments section provided below.
- See more at: https://www.apptha.com/blog/magento-url-redirect-from-controller/#sthash.Q32pioEf.dpuf更多推荐
所有评论(0)