1

I have one phtml.

In there i m check one variable if that variable is null than it should be redirect to Controller action

I m trying this code:

Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl().'marketplace/vendor/selectcategory'); 

but using this code if variable is not null than also redirect but i don't want this. I need to redirect when variable is null

2
  • how you are assigning value to variable & also how you are checking your variable for null value ? please add all the related code
    – Ahmed
    May 14, 2015 at 11:52
  • I m getting int value using post method
    – ND17
    May 14, 2015 at 13:03

2 Answers 2

8

Please try this...

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl().'marketplace/vendor/selectcategory');

exit()

better way to use JavaScript:

<script type="text/javascript">location.href = '<?php echo Mage::getBaseUrl().'marketplace/vendor/selectcategory';  ?>';</script>
5

You should not do redirects from the template files.
You should do it form the controller before calling $this->renderLayout().
Do something like this in your controller:

if (your condition here) {
     $this->_redirect('marketplace/vendor/selectcategory');
     return;
}
2
  • it gives error like this ` a:5:{i:0;s:127:"Invalid method Example_Marketplace_Block_Vendoraddproducts::_redirect(Array ( [0] => marketplace/vendor/selectcategory )`
    – ND17
    May 14, 2015 at 13:02
  • 1
    _redirect is function of controller,is not function of block
    – Amit Bera
    May 14, 2015 at 13:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.