Magento – Fix Adminhtml Redirection Issue from Controller

adminhtmlcontrollersredirect

In a module I created a new file type product option. The goal was to add a "file is valid" parameter.

With this option, I can define in the admin panel the option "is valid" state from the order detail view page and a button permits to submit the state change via a controller.

I would like after submission to be redirected to the order detail view page.

I tried $this->_redirect('*/*'); but get 404 error

my option phtml
(app/design/adminhtml/default/default/template/custoptiontypev6/options/customview/xfile.phtml)

    ...
    <span>
        <FORM id="xfile_state_sel" method="post" style="margin: 0px 5px 0px 15px;" action="<?php echo Mage::helper("adminhtml")->getUrl("custoptiontypev6/xfile/update");?>">
            <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
            <input name="order_id" type="hidden" value="<?php echo $_order_id ?>" />
            <input name="item_id" type="hidden" value="<?php echo $_item_id ?>" />
            <input name="option_id" type="hidden" value="<?php echo $_optionid ?>" />
            <input name="option_label" type="hidden" value="<?php echo $_label ?>" />
            <INPUT type= "radio" name="<?php echo 'Xfile_option_'.$_optionid.'_'.$_label;?>" value="Checking" <?php echo $_checked_verif;?>> Being verified
            <INPUT type= "radio" name="<?php echo 'Xfile_option_'.$_optionid.'_'.$_label;?>" value="Files_OK" <?php echo $_checked_ok;?>> Files OK
            <INPUT type= "radio" name="<?php echo 'Xfile_option_'.$_optionid.'_'.$_label;?>" value="Files_not_OK" <?php echo $_checked_notok;?>> Files not OK
            <span><button type="submit" style="margin: 0px 5px 0px 15px;">Update state</button></span>
        </FORM>
</span>

The controller :

<?php
class Mine_Custoptiontypev6_XfileController extends Mage_Adminhtml_Controller_Action
{
    public function updateAction()
    {
        $post = $this->getRequest()->getPost();
        try {
            if (empty($post)) {
                //echo 'Invalid form data.';
            }

            /******* form processing *******/

    ...

        $this->_redirect('*/*');
    }  
}
?>

Thank you for your help,

Best Answer

When redirecting * means current, so with $this->_redirect('*/*'); you are targeting the current module, current controller and index action. As I see a closing ?> in your controller (which by the way you should exclude, see here) I'm going to assume you have no more actions in that controller, including the index action, therefore the redirect fails in a 404 because the action does not actually exist.

You need to redirect to the adminhtml module, sales_order controller and view action instead so use the following:

$this->_redirect('adminhtml/sales_order/view', array('order_id' => $someorderid));
Related Topic