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:


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

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

2 Answers 2


Please try this...



better way to use JavaScript:

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

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) {
  • it gives error like this ` a:5:{i:0;s:127:"Invalid method Example_Marketplace_Block_Vendoraddproducts::_redirect(Array ( [0] => marketplace/vendor/selectcategory )`
    – ND17
    Commented May 14, 2015 at 13:02
  • 1
    _redirect is function of controller,is not function of block
    – Amit Bera
    Commented 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.