Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Simple Redirect
 
bcelenza
Member
 
Avatar
Total Posts:  44
Joined:  2008-08-27
 

Hey all,

I’m trying to figure out how to do a simple page redirect in one of my controllers. If a session variable comes back empty, I want to redirect them to a different page in magento. The magento equivalent of php’s “header(’Location: ‘)” function.

I see the inherited _redirect() and _redirectUrl() methods from within my controller, but cannot get them to work, so I’m assuming those are different from what I want. I figure I’m probably missing something obvious.

Thanks in advance! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
bcelenza
Member
 
Avatar
Total Posts:  44
Joined:  2008-08-27
 

Solution found. Thanks anyway.

$this->getResponse()->setRedirect($url);

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

The funny thing is, $this->_redirectUrl($url) == $this->getResponse()->setRedirect($url)

If you tried $this->_redirectUrl() and had problems that are gone with $this->getResponse()->setRedirect($url), then you had some other problem you fixed along the way.

 
Magento Community Magento Community
Magento Community
Magento Community
 
illo_sdrawkcab
Member
 
Total Posts:  63
Joined:  2008-10-23
 

This thread is old but i had a problem with my redirect. I simply want to redirect to last seen product after adding it to the cart with my own module direct order ( you can quickly add a product by sku )

$backUrl $this->_getRefererUrl();
$this->getResponse()->setRedirect($backUrl);

This i picked from the cartController.php. In Backend redirect_to_cart is turned off so i thought this would redirect but if i call my module it throws the following error:

SQLSTATE[HY093]Invalid parameter numberno parameters were bound
Trace
:
#0 /storage01/httpd/php5/magento/lib/Zend/Db/Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 /storage01/httpd/php5/magento/lib/Zend/Db/Adapter/Abstract.php(406): Zend_Db_Statement->execute(Array)
#2 /storage01/httpd/php5/magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(206): Zend_Db_Adapter_Abstract->query(Object(Varien_Db_Select), Array)
#3 /storage01/httpd/php5/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(230): Zend_Db_Adapter_Pdo_Abstract->query(Object(Varien_Db_Select), Array)
#4 /storage01/httpd/php5/magento/lib/Zend/Db/Adapter/Abstract.php(636): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
#5 /storage01/httpd/php5/magento/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(303): Zend_Db_Adapter_Abstract->fetchRow(Object(Varien_Db_Select))
#6 /storage01/httpd/php5/magento/app/code/core/Mage/Core/Model/Abstract.php(207): Mage_Core_Model_Mysql4_Abstract->load(Object(Mage_Core_Model_Url_Rewrite), 'checkout/cart/a...', 'request_path')
#7 /storage01/httpd/php5/magento/app/code/core/Mage/Core/Model/Url/Rewrite.php(62): Mage_Core_Model_Abstract->load('checkout/cart/a...', 'request_path')
#8 /storage01/httpd/php5/magento/app/code/core/Mage/Core/Model/Url/Rewrite.php(192): Mage_Core_Model_Url_Rewrite->loadByRequestPath(Array)
#9 /storage01/httpd/php5/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(166): Mage_Core_Model_Url_Rewrite->rewrite()
#10 /storage01/httpd/php5/magento/app/Mage.php(447): Mage_Core_Controller_Varien_Front->dispatch()
#11 /storage01/httpd/php5/magento/index.php(52): Mage::run()
#12 {main}

can somebody help me ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top